Declaring variables from a list
#1
hi,

if i got a list is it possible to declare a variable from the items in that list?

Quote:blob = ['var1', 'var2', 'var3']
i = 5
for listitems in blob:
    i += 1
    listitems = i

print var1
6
print var2
7
print var3
8

something like that? this doesn't work (obviously) but is there a way to do this?

tia,
cacti
Reply
#2
this is the first time i've seen a dev question in the request forum.... seemingly its always the other way around...

the easiest thing to do in a case like this is to add objects to the list and change a member value in the for loop. that way the object kinda holds the value although you arent changing the object.
Reply
#3
thanks for the reply. now my question is how i convert a string to an object.

oh, and sorry if i posted in the wrong section.

/moi
Reply
#4
python doesnt really have types or anything... you should probably be able to do it like this...

class something():
def (self,value):
self.val = value

obj = something("foo")
print obj.val
obj.val = "bar"
print obj.val


this may not be exactly right and you might not even need to specify a constructor...
Reply

Logout Mark Read Team Forum Stats Members Help
Declaring variables from a list0