On 7/14/06, Сергій <[EMAIL PROTECTED]> wrote:
suppose I need to create 1000 000 variables
var_1, var_2, .... var_1000000
 
how to do this using for?
(something like
for i in range(1000000):
___var_


You should think about not creating variables like this, it is bad programming and continuing to use similar techniques leads you down the path of buggy code and hours of trying to trace your code.

That being said, here's a nice, safe solution:

# get the current module
import sys
cur_module = sys.module[__name__]
for i in range(1000000):
    cur_module['var_%s' % i] = i # var_i = i
print var_46889  # in the current namespace

But again, like others have suggested, you should rethink your problem and your solution before starting down your path.  What are you really capturing?
  -Arcege
--
There's so many different worlds,
So many different suns.
And we have just one world,
But we live in different ones.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to