Python; Converting a list into separate strings -


i'm trying read file have stored numbers in. arranged so:

1, 2, 4, 5, 6, 7, 8, 9, 2, 1, 2, 3, 4

i'm trying turn numbers individual strings.

i've written read file code , can whole text 1 string, cannot make them individual.

for example output need is:

var1=1 var2=2 var3=4 etc etc

thanks help

>>> open('nums.txt') f:         nums = [int(n) n in f.readline().split(', ')]   >>> nums [1, 2, 4, 5, 6, 7, 8, 9, 2, 1, 2, 3, 4] 

as @amber noted can use csv module this:

>>> import csv >>> open('nums.txt') f:         r = csv.reader(f)         nums = [int(n) n in next(r)]   >>> nums [1, 2, 4, 5, 6, 7, 8, 9, 2, 1, 2, 3, 4] 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -