Using String for new List name
olof.bjarnason at gmail.com
Mon Sep 28 18:59:41 CEST 2009
2009/9/28 Scott <scott.freemire at gmail.com>:
> I am new to Python but I have studied hard and written a fairly big
> (to me) script/program. I have solved all of my problems by Googling
> but this one has got me stumped.
> I want to check a string for a substring and if it exists I want to
> create a new, empty list using that substring as the name of the list.
> For example:
What do you mean by "as the name of the list"?
You cannot alter the name "Z" in the source code to be the content of
the file, unless you do some serious magic ;)
> Let's say file1 has line1 through line100 as the first word in each
> for X in open("file1"):
> Do a test.
> If true:
> Y = re.split(" ", X)
> Z = Y # This is a string, maybe it is "Line42"
> Z =  # This doesn't work, I want a new, empty
> list created called Line42 not Z.
> Is there any way to do this?
More information about the Python-list