How to print a specific line in a csv file that is not named csv in python?
I'm supposed to write a function that does this specifically.
def get_customer_record(file_handle, n):
"""
-------------------------------------------------------
Find the n-th record in a comma-delimited sequential file.
Records are numbered starting with 0.
Use: result = get_customer_record(file_handle, n)
-------------------------------------------------------
Parameters:
file_handle - file to search (file - open for reading)
n - the number of the record to return (int > 0)
Returns:
result - a list of the fields of the n-th record if it exists,
an empty list otherwise (list)
-------------------------------------------------------
"""
And here is the file.
customers.txt
12345,Tom,Black,300.00,1998-01-30
23456,Alice,Smith,1200.50,1998-02-20
14567,Jane,White,900.00,1998-07-01
43564,Weilin,Zhao,450.25,1998-01-03
45432,Bina,Mehta,278.95,1998-03-21
The Code
list =
file_handle = open('customers.txt', 'r+', encoding="utf-8")
line = file_handle.readline(n)
list.append(line.strip(','))
file_handle.close()
return list
python
|
show 2 more comments
I'm supposed to write a function that does this specifically.
def get_customer_record(file_handle, n):
"""
-------------------------------------------------------
Find the n-th record in a comma-delimited sequential file.
Records are numbered starting with 0.
Use: result = get_customer_record(file_handle, n)
-------------------------------------------------------
Parameters:
file_handle - file to search (file - open for reading)
n - the number of the record to return (int > 0)
Returns:
result - a list of the fields of the n-th record if it exists,
an empty list otherwise (list)
-------------------------------------------------------
"""
And here is the file.
customers.txt
12345,Tom,Black,300.00,1998-01-30
23456,Alice,Smith,1200.50,1998-02-20
14567,Jane,White,900.00,1998-07-01
43564,Weilin,Zhao,450.25,1998-01-03
45432,Bina,Mehta,278.95,1998-03-21
The Code
list =
file_handle = open('customers.txt', 'r+', encoding="utf-8")
line = file_handle.readline(n)
list.append(line.strip(','))
file_handle.close()
return list
python
1
So what have you tried so far? In what way is it not working?
– Kingsley
Nov 21 at 2:21
Welcome to Stack Overflow! Please take the tour, look around, and read through the Help Center, in particular How do I ask a good question? If you run into a specific problem, research it thoroughly, search thoroughly here, and if you're still stuck post your code and a description of the problem. Also, remember to include Minimum, Complete, Verifiable Example. People will be glad to help
– Andreas
Nov 21 at 2:22
Welcome to SO, we are a community of volunteers that help answer questions/issues in code. Unfortunately I see no code here, we don't write programs. Please try to answer this yourself and come back if you run into any issues. Don't be afraid to search your question/issue before asking
– Jaba
Nov 21 at 2:22
Maybe it would help to read about python's CSV Module - docs.python.org/3/library/csv.html or perhaps Python's input and output syntax - docs.python.org/3/tutorial/inputoutput.html
– Kingsley
Nov 21 at 2:24
@Kingsley list = file_handle = open('customers.txt', 'r+', encoding="utf-8") line = file_handle.readline(n) list.append(line.strip(',')) file_handle.close() return list I have tried doing this, here was what I have in my testing file. from functions import get_customer_record file_handle = open('customers.txt', 'r+', encoding="utf-8") n = int(input()) result = get_customer_record(file_handle, n) print(list)
– David Enjugu
Nov 21 at 2:27
|
show 2 more comments
I'm supposed to write a function that does this specifically.
def get_customer_record(file_handle, n):
"""
-------------------------------------------------------
Find the n-th record in a comma-delimited sequential file.
Records are numbered starting with 0.
Use: result = get_customer_record(file_handle, n)
-------------------------------------------------------
Parameters:
file_handle - file to search (file - open for reading)
n - the number of the record to return (int > 0)
Returns:
result - a list of the fields of the n-th record if it exists,
an empty list otherwise (list)
-------------------------------------------------------
"""
And here is the file.
customers.txt
12345,Tom,Black,300.00,1998-01-30
23456,Alice,Smith,1200.50,1998-02-20
14567,Jane,White,900.00,1998-07-01
43564,Weilin,Zhao,450.25,1998-01-03
45432,Bina,Mehta,278.95,1998-03-21
The Code
list =
file_handle = open('customers.txt', 'r+', encoding="utf-8")
line = file_handle.readline(n)
list.append(line.strip(','))
file_handle.close()
return list
python
I'm supposed to write a function that does this specifically.
def get_customer_record(file_handle, n):
"""
-------------------------------------------------------
Find the n-th record in a comma-delimited sequential file.
Records are numbered starting with 0.
Use: result = get_customer_record(file_handle, n)
-------------------------------------------------------
Parameters:
file_handle - file to search (file - open for reading)
n - the number of the record to return (int > 0)
Returns:
result - a list of the fields of the n-th record if it exists,
an empty list otherwise (list)
-------------------------------------------------------
"""
And here is the file.
customers.txt
12345,Tom,Black,300.00,1998-01-30
23456,Alice,Smith,1200.50,1998-02-20
14567,Jane,White,900.00,1998-07-01
43564,Weilin,Zhao,450.25,1998-01-03
45432,Bina,Mehta,278.95,1998-03-21
The Code
list =
file_handle = open('customers.txt', 'r+', encoding="utf-8")
line = file_handle.readline(n)
list.append(line.strip(','))
file_handle.close()
return list
python
python
edited Nov 21 at 2:34
Kingsley
2,27711023
2,27711023
asked Nov 21 at 2:17
David Enjugu
11
11
1
So what have you tried so far? In what way is it not working?
– Kingsley
Nov 21 at 2:21
Welcome to Stack Overflow! Please take the tour, look around, and read through the Help Center, in particular How do I ask a good question? If you run into a specific problem, research it thoroughly, search thoroughly here, and if you're still stuck post your code and a description of the problem. Also, remember to include Minimum, Complete, Verifiable Example. People will be glad to help
– Andreas
Nov 21 at 2:22
Welcome to SO, we are a community of volunteers that help answer questions/issues in code. Unfortunately I see no code here, we don't write programs. Please try to answer this yourself and come back if you run into any issues. Don't be afraid to search your question/issue before asking
– Jaba
Nov 21 at 2:22
Maybe it would help to read about python's CSV Module - docs.python.org/3/library/csv.html or perhaps Python's input and output syntax - docs.python.org/3/tutorial/inputoutput.html
– Kingsley
Nov 21 at 2:24
@Kingsley list = file_handle = open('customers.txt', 'r+', encoding="utf-8") line = file_handle.readline(n) list.append(line.strip(',')) file_handle.close() return list I have tried doing this, here was what I have in my testing file. from functions import get_customer_record file_handle = open('customers.txt', 'r+', encoding="utf-8") n = int(input()) result = get_customer_record(file_handle, n) print(list)
– David Enjugu
Nov 21 at 2:27
|
show 2 more comments
1
So what have you tried so far? In what way is it not working?
– Kingsley
Nov 21 at 2:21
Welcome to Stack Overflow! Please take the tour, look around, and read through the Help Center, in particular How do I ask a good question? If you run into a specific problem, research it thoroughly, search thoroughly here, and if you're still stuck post your code and a description of the problem. Also, remember to include Minimum, Complete, Verifiable Example. People will be glad to help
– Andreas
Nov 21 at 2:22
Welcome to SO, we are a community of volunteers that help answer questions/issues in code. Unfortunately I see no code here, we don't write programs. Please try to answer this yourself and come back if you run into any issues. Don't be afraid to search your question/issue before asking
– Jaba
Nov 21 at 2:22
Maybe it would help to read about python's CSV Module - docs.python.org/3/library/csv.html or perhaps Python's input and output syntax - docs.python.org/3/tutorial/inputoutput.html
– Kingsley
Nov 21 at 2:24
@Kingsley list = file_handle = open('customers.txt', 'r+', encoding="utf-8") line = file_handle.readline(n) list.append(line.strip(',')) file_handle.close() return list I have tried doing this, here was what I have in my testing file. from functions import get_customer_record file_handle = open('customers.txt', 'r+', encoding="utf-8") n = int(input()) result = get_customer_record(file_handle, n) print(list)
– David Enjugu
Nov 21 at 2:27
1
1
So what have you tried so far? In what way is it not working?
– Kingsley
Nov 21 at 2:21
So what have you tried so far? In what way is it not working?
– Kingsley
Nov 21 at 2:21
Welcome to Stack Overflow! Please take the tour, look around, and read through the Help Center, in particular How do I ask a good question? If you run into a specific problem, research it thoroughly, search thoroughly here, and if you're still stuck post your code and a description of the problem. Also, remember to include Minimum, Complete, Verifiable Example. People will be glad to help
– Andreas
Nov 21 at 2:22
Welcome to Stack Overflow! Please take the tour, look around, and read through the Help Center, in particular How do I ask a good question? If you run into a specific problem, research it thoroughly, search thoroughly here, and if you're still stuck post your code and a description of the problem. Also, remember to include Minimum, Complete, Verifiable Example. People will be glad to help
– Andreas
Nov 21 at 2:22
Welcome to SO, we are a community of volunteers that help answer questions/issues in code. Unfortunately I see no code here, we don't write programs. Please try to answer this yourself and come back if you run into any issues. Don't be afraid to search your question/issue before asking
– Jaba
Nov 21 at 2:22
Welcome to SO, we are a community of volunteers that help answer questions/issues in code. Unfortunately I see no code here, we don't write programs. Please try to answer this yourself and come back if you run into any issues. Don't be afraid to search your question/issue before asking
– Jaba
Nov 21 at 2:22
Maybe it would help to read about python's CSV Module - docs.python.org/3/library/csv.html or perhaps Python's input and output syntax - docs.python.org/3/tutorial/inputoutput.html
– Kingsley
Nov 21 at 2:24
Maybe it would help to read about python's CSV Module - docs.python.org/3/library/csv.html or perhaps Python's input and output syntax - docs.python.org/3/tutorial/inputoutput.html
– Kingsley
Nov 21 at 2:24
@Kingsley list = file_handle = open('customers.txt', 'r+', encoding="utf-8") line = file_handle.readline(n) list.append(line.strip(',')) file_handle.close() return list I have tried doing this, here was what I have in my testing file. from functions import get_customer_record file_handle = open('customers.txt', 'r+', encoding="utf-8") n = int(input()) result = get_customer_record(file_handle, n) print(list)
– David Enjugu
Nov 21 at 2:27
@Kingsley list = file_handle = open('customers.txt', 'r+', encoding="utf-8") line = file_handle.readline(n) list.append(line.strip(',')) file_handle.close() return list I have tried doing this, here was what I have in my testing file. from functions import get_customer_record file_handle = open('customers.txt', 'r+', encoding="utf-8") n = int(input()) result = get_customer_record(file_handle, n) print(list)
– David Enjugu
Nov 21 at 2:27
|
show 2 more comments
2 Answers
2
active
oldest
votes
A simple solution would be iterate through the file using next()
:
from csv import reader
def get_customer_record(file_handle, n):
with open(file=file_handle) as csvfile:
csv_reader = reader(csvfile)
return next((line for row, line in enumerate(csv_reader) if row == n), )
print(get_customer_record(file_handle='customer.csv', n=3))
# ['43564', 'Weilin', 'Zhao', '450.25', '1998-01-03']
print(get_customer_record(file_handle='customer.csv', n=5))
#
add a comment |
It's not clear from your syntax whether to return just the row as a string, or the fields split around the ,
. I have assumed the single-line.
The python readline()
function does not take an index, it just reads the next line from the file. Below I used readlines()
(note the s
) which reads all lines from the file. If your file was huge, this would not be so efficient.
Also a bit of error-handling for out-of-bounds n
helps:
def get_customer_record(file_handle, n):
lines = file_handle.readlines()
if (n >= 0 and n < len(lines)):
return lines[n] # or n-1?
else:
return None
file_handle = open( 'customers.txt', 'r+', encoding="utf-8" )
fields = get_customer_record( file_handle, 3 )
print( str( fields ) )
Of course you may not want to read the whole file, just the next Nth record
def get_customer_record(file_handle, n):
if (n >= 0):
line = file_handle.readline()
while (n > 0):
line = file_handle.readline()
if (line == ''):
line = None
break # end of file
n -= 1
return line
else:
return None
Obviously this code assumes that n
is indexed 0 -> (N-1).
Really appreciate the help, my only question is why did you use 3? in the line fields = get..... Thank you
– David Enjugu
Nov 21 at 3:02
@DavidEnjugu I used 3 just as a test number, no particular reason. But FWIW I tested with 0, 5, 50 and -4 too.
– Kingsley
Nov 21 at 7:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404427%2fhow-to-print-a-specific-line-in-a-csv-file-that-is-not-named-csv-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
A simple solution would be iterate through the file using next()
:
from csv import reader
def get_customer_record(file_handle, n):
with open(file=file_handle) as csvfile:
csv_reader = reader(csvfile)
return next((line for row, line in enumerate(csv_reader) if row == n), )
print(get_customer_record(file_handle='customer.csv', n=3))
# ['43564', 'Weilin', 'Zhao', '450.25', '1998-01-03']
print(get_customer_record(file_handle='customer.csv', n=5))
#
add a comment |
A simple solution would be iterate through the file using next()
:
from csv import reader
def get_customer_record(file_handle, n):
with open(file=file_handle) as csvfile:
csv_reader = reader(csvfile)
return next((line for row, line in enumerate(csv_reader) if row == n), )
print(get_customer_record(file_handle='customer.csv', n=3))
# ['43564', 'Weilin', 'Zhao', '450.25', '1998-01-03']
print(get_customer_record(file_handle='customer.csv', n=5))
#
add a comment |
A simple solution would be iterate through the file using next()
:
from csv import reader
def get_customer_record(file_handle, n):
with open(file=file_handle) as csvfile:
csv_reader = reader(csvfile)
return next((line for row, line in enumerate(csv_reader) if row == n), )
print(get_customer_record(file_handle='customer.csv', n=3))
# ['43564', 'Weilin', 'Zhao', '450.25', '1998-01-03']
print(get_customer_record(file_handle='customer.csv', n=5))
#
A simple solution would be iterate through the file using next()
:
from csv import reader
def get_customer_record(file_handle, n):
with open(file=file_handle) as csvfile:
csv_reader = reader(csvfile)
return next((line for row, line in enumerate(csv_reader) if row == n), )
print(get_customer_record(file_handle='customer.csv', n=3))
# ['43564', 'Weilin', 'Zhao', '450.25', '1998-01-03']
print(get_customer_record(file_handle='customer.csv', n=5))
#
answered Nov 21 at 3:08
RoadRunner
10.1k31340
10.1k31340
add a comment |
add a comment |
It's not clear from your syntax whether to return just the row as a string, or the fields split around the ,
. I have assumed the single-line.
The python readline()
function does not take an index, it just reads the next line from the file. Below I used readlines()
(note the s
) which reads all lines from the file. If your file was huge, this would not be so efficient.
Also a bit of error-handling for out-of-bounds n
helps:
def get_customer_record(file_handle, n):
lines = file_handle.readlines()
if (n >= 0 and n < len(lines)):
return lines[n] # or n-1?
else:
return None
file_handle = open( 'customers.txt', 'r+', encoding="utf-8" )
fields = get_customer_record( file_handle, 3 )
print( str( fields ) )
Of course you may not want to read the whole file, just the next Nth record
def get_customer_record(file_handle, n):
if (n >= 0):
line = file_handle.readline()
while (n > 0):
line = file_handle.readline()
if (line == ''):
line = None
break # end of file
n -= 1
return line
else:
return None
Obviously this code assumes that n
is indexed 0 -> (N-1).
Really appreciate the help, my only question is why did you use 3? in the line fields = get..... Thank you
– David Enjugu
Nov 21 at 3:02
@DavidEnjugu I used 3 just as a test number, no particular reason. But FWIW I tested with 0, 5, 50 and -4 too.
– Kingsley
Nov 21 at 7:52
add a comment |
It's not clear from your syntax whether to return just the row as a string, or the fields split around the ,
. I have assumed the single-line.
The python readline()
function does not take an index, it just reads the next line from the file. Below I used readlines()
(note the s
) which reads all lines from the file. If your file was huge, this would not be so efficient.
Also a bit of error-handling for out-of-bounds n
helps:
def get_customer_record(file_handle, n):
lines = file_handle.readlines()
if (n >= 0 and n < len(lines)):
return lines[n] # or n-1?
else:
return None
file_handle = open( 'customers.txt', 'r+', encoding="utf-8" )
fields = get_customer_record( file_handle, 3 )
print( str( fields ) )
Of course you may not want to read the whole file, just the next Nth record
def get_customer_record(file_handle, n):
if (n >= 0):
line = file_handle.readline()
while (n > 0):
line = file_handle.readline()
if (line == ''):
line = None
break # end of file
n -= 1
return line
else:
return None
Obviously this code assumes that n
is indexed 0 -> (N-1).
Really appreciate the help, my only question is why did you use 3? in the line fields = get..... Thank you
– David Enjugu
Nov 21 at 3:02
@DavidEnjugu I used 3 just as a test number, no particular reason. But FWIW I tested with 0, 5, 50 and -4 too.
– Kingsley
Nov 21 at 7:52
add a comment |
It's not clear from your syntax whether to return just the row as a string, or the fields split around the ,
. I have assumed the single-line.
The python readline()
function does not take an index, it just reads the next line from the file. Below I used readlines()
(note the s
) which reads all lines from the file. If your file was huge, this would not be so efficient.
Also a bit of error-handling for out-of-bounds n
helps:
def get_customer_record(file_handle, n):
lines = file_handle.readlines()
if (n >= 0 and n < len(lines)):
return lines[n] # or n-1?
else:
return None
file_handle = open( 'customers.txt', 'r+', encoding="utf-8" )
fields = get_customer_record( file_handle, 3 )
print( str( fields ) )
Of course you may not want to read the whole file, just the next Nth record
def get_customer_record(file_handle, n):
if (n >= 0):
line = file_handle.readline()
while (n > 0):
line = file_handle.readline()
if (line == ''):
line = None
break # end of file
n -= 1
return line
else:
return None
Obviously this code assumes that n
is indexed 0 -> (N-1).
It's not clear from your syntax whether to return just the row as a string, or the fields split around the ,
. I have assumed the single-line.
The python readline()
function does not take an index, it just reads the next line from the file. Below I used readlines()
(note the s
) which reads all lines from the file. If your file was huge, this would not be so efficient.
Also a bit of error-handling for out-of-bounds n
helps:
def get_customer_record(file_handle, n):
lines = file_handle.readlines()
if (n >= 0 and n < len(lines)):
return lines[n] # or n-1?
else:
return None
file_handle = open( 'customers.txt', 'r+', encoding="utf-8" )
fields = get_customer_record( file_handle, 3 )
print( str( fields ) )
Of course you may not want to read the whole file, just the next Nth record
def get_customer_record(file_handle, n):
if (n >= 0):
line = file_handle.readline()
while (n > 0):
line = file_handle.readline()
if (line == ''):
line = None
break # end of file
n -= 1
return line
else:
return None
Obviously this code assumes that n
is indexed 0 -> (N-1).
edited Nov 21 at 2:48
answered Nov 21 at 2:39
Kingsley
2,27711023
2,27711023
Really appreciate the help, my only question is why did you use 3? in the line fields = get..... Thank you
– David Enjugu
Nov 21 at 3:02
@DavidEnjugu I used 3 just as a test number, no particular reason. But FWIW I tested with 0, 5, 50 and -4 too.
– Kingsley
Nov 21 at 7:52
add a comment |
Really appreciate the help, my only question is why did you use 3? in the line fields = get..... Thank you
– David Enjugu
Nov 21 at 3:02
@DavidEnjugu I used 3 just as a test number, no particular reason. But FWIW I tested with 0, 5, 50 and -4 too.
– Kingsley
Nov 21 at 7:52
Really appreciate the help, my only question is why did you use 3? in the line fields = get..... Thank you
– David Enjugu
Nov 21 at 3:02
Really appreciate the help, my only question is why did you use 3? in the line fields = get..... Thank you
– David Enjugu
Nov 21 at 3:02
@DavidEnjugu I used 3 just as a test number, no particular reason. But FWIW I tested with 0, 5, 50 and -4 too.
– Kingsley
Nov 21 at 7:52
@DavidEnjugu I used 3 just as a test number, no particular reason. But FWIW I tested with 0, 5, 50 and -4 too.
– Kingsley
Nov 21 at 7:52
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404427%2fhow-to-print-a-specific-line-in-a-csv-file-that-is-not-named-csv-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
So what have you tried so far? In what way is it not working?
– Kingsley
Nov 21 at 2:21
Welcome to Stack Overflow! Please take the tour, look around, and read through the Help Center, in particular How do I ask a good question? If you run into a specific problem, research it thoroughly, search thoroughly here, and if you're still stuck post your code and a description of the problem. Also, remember to include Minimum, Complete, Verifiable Example. People will be glad to help
– Andreas
Nov 21 at 2:22
Welcome to SO, we are a community of volunteers that help answer questions/issues in code. Unfortunately I see no code here, we don't write programs. Please try to answer this yourself and come back if you run into any issues. Don't be afraid to search your question/issue before asking
– Jaba
Nov 21 at 2:22
Maybe it would help to read about python's CSV Module - docs.python.org/3/library/csv.html or perhaps Python's input and output syntax - docs.python.org/3/tutorial/inputoutput.html
– Kingsley
Nov 21 at 2:24
@Kingsley list = file_handle = open('customers.txt', 'r+', encoding="utf-8") line = file_handle.readline(n) list.append(line.strip(',')) file_handle.close() return list I have tried doing this, here was what I have in my testing file. from functions import get_customer_record file_handle = open('customers.txt', 'r+', encoding="utf-8") n = int(input()) result = get_customer_record(file_handle, n) print(list)
– David Enjugu
Nov 21 at 2:27