Re: Variable Variable

2005-03-20 Thread Mike Gould
Premshree Pillai wrote:
On Sat, 19 Mar 2005 04:35:47 -0500, Leif K-Brooks <[EMAIL PROTECTED]> wrote:
Tanteauguri wrote:
Hi List, is there in python a variable variable like in PHP ($$var)?
What I want to do is something like that:
pc=["a","b","c"]
for i in pc:
   i = anyclass()
a.shutdown()
b.update()
Use a dictionary:
stuff = {}
pc = ['a', 'b', 'c']

I think what he wants to do is basically hold object names in a tuple
list, and then call the methods on those objects (while iterating or
whatever).

for i in pc:
stuff[i] = anyclass()
stuff['a'].shutdown()
stuff['b'].update()
--
http://mail.python.org/mailman/listinfo/python-list

Try this:
pc=["a","b","c"]
for i in pc:
vars()[i] = anyclass()
a.shutdown()
b.update()
MikeG
--
http://mail.python.org/mailman/listinfo/python-list


Shell re-direction

2005-03-20 Thread Mike Gould
Hi all,
I have a very strange problem with the output run from commands run via 
os.system().  If the python script is run without re-direction the 
output appears as expected, but if I re-direct the output from the 
script the output gets re-ordered.

For example given the following script:
import os
print '1'
os.system('echo 2')
print '3'
$ python test.py
1
2
3
$ python test.py | cat
2
1
3
Can anyone explain what's going on here?
Thanks
Mike
--
http://mail.python.org/mailman/listinfo/python-list