I am trying to use enumerate()
on a string already in memory (thus not from file), which string has comma separated values (or space, but uniformly, i.e. not mix of comma and spaces).
Basically I just want to get the whole line n, something quite similar to the first part of this question.
If I do a print
on my string (before entering the function), it shows something like this:
89,abc,def01,ghi23
01,jkl,mno45,pqr67
however this code does not work, presumably because my lines are not individually surrounded by quotes:
def pickline(thestring, whatline):
for i, line in enumerate(thestring):
if i == whatline:
return line
Question: what should I do to get this right ?
edit The expected output should be:
# string
89,abc,def01,ghi23
# if whatline value is 0,
# or string
01,jkl,mno45,pqr67
# if whatline value is 1,
# etc.