← Back to team overview

yade-dev team mailing list archive

Re: evaluating expressions in python

 

Thank you. I get the logic (I also get declaring and defining at the same time is the source of all mess). I'm afraid I'll still need your help as it seems what usualy works doesn't in Yade case. I tried the same code as below in a standalone python console : no problem. In Yade however, there seem to be still a scope issue and the declared global is not found. I suspect something with "modules", or something specific to Ipython... any idea?

Bruno


Yade [18]: tt=1
Yade [19]: def changett():
....: global tt
....: tt+=1
....: print tt
....: tt=10
....: print tt
....:
Yade [20]: tt
-> [20]: 1
Yade [21]: changett()
---------------------------------------------------------------------------
<type 'exceptions.NameError'> Traceback (most recent call last)

/home/bruno/YADE/bin/<ipython console> in <module>()

/home/bruno/YADE/bin/<ipython console> in changett()

<type 'exceptions.NameError'>: global name 'tt' is not defined








Václav Šmilauer a écrit :
A small python question. Anyone got this problem before?
different scopes, different variables
http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces

google out the "global" keyword for a workaround.



_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to     : yade-dev@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~yade-dev
More help   : https://help.launchpad.net/ListHelp



--
_______________
Bruno Chareyre
Associate Professor
Grenoble INP
Lab. 3SR
BP 53 - 38041, Grenoble cedex 9 - France
Tél : 33 4 56 52 86 21
Fax : 33 4 76 82 70 43
________________




Follow ups

References