Hello all.
 
Thanks for the tips and solutions posted to the list so far.  This is a general python question, not windows specific.  It is my turn to ask. (Perhaps the notion below will suggest some development to one of you. Who knows?)
 
I want to execute a statement indirectly in Python. Take the simple case below.  The chevrons ">> " indicate the result of the statement
b = 2
a = b + 6
eval('a = b + 6', globals(), locals() )
>>   File "not_much_at_all.py", line 21, in ?
>>       rslt = eval('a = b + 6', globals(), locals() )
>>   File "<string>", line 1
>>     a = b + 6
>>       ^
>> SyntaxError: invalid syntax
While I appreciate that "eval()" is not the way to do this, it is also true that "eval()" accurately signals my intention in this sample.
 
HOW -- or, is it possible -- to execute the an assignment statement from a string?
 
I have used compile() and considered using a 'block'.  Compile doesn't help.  And I can't find an equivalent for 'eval( <block> )' ...
 
Who has the answer?
 
Many thanks in advance.
 
Cheers,
              Will.
 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.9.3 - Release Date: 5/Apr/2005
_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to