Use list name as string

MRAB google at
Wed Feb 4 12:07:19 EST 2009

Vincent Davis wrote:
 > Sorry for not being clear I would have something like this x = [1, 2,
 > 3,5 ,6 ,9,234]
 > Then def savedata(dataname): ..........
 > savedata(x)
 > this would save a to a file called x.csv This is my problem, getting
 > the name to be x.csv which is the same as the name of the list.
 > and the data in the file would be 1,2,3,5,6,9,234 this parts works
The list itself doesn't have a name. You need to pass in both the name
and the list:

def savedata(name, data): ..........

savedata("x", x)

More information about the Python-list mailing list