Feb-07-2020, 06:34 PM
Hello again,
Wondering why I can't get this to work...
I have a list of numerical values stored in a .txt file lib.txt, like this:
The end goal is to make a continuous loop that looks at each item in the list; passing each one as an argument to be used by another function.
Here's what I am trying to do:
In python 3.6 I can't do the
The second problem is that when I do get something working, it usually prints the entire line, not each of the individual comma separated values per line.
Finally, would this be the proper syntax to pass each item in the list off to be used as an argument in another function?
Wondering why I can't get this to work...
I have a list of numerical values stored in a .txt file lib.txt, like this:
374837, 387473, 384895, 283473I would like to open this file, and iterate through each item in the list, to be used as an argument in another function.
The end goal is to make a continuous loop that looks at each item in the list; passing each one as an argument to be used by another function.
Here's what I am trying to do:
def iterateList(): li=open('lib.txt').readlines() li=list(li.split(',')) print(li)I'm running into a few issues:
In python 3.6 I can't do the
li=list(li.split(','))line (i'm guessing because it's not a string. But when I convert the list to a string, it will then show as a list inside of another list, or a set of lists.
The second problem is that when I do get something working, it usually prints the entire line, not each of the individual comma separated values per line.
Finally, would this be the proper syntax to pass each item in the list off to be used as an argument in another function?
for i in li: otherFunction(i)Any advice or tips are appreciated!