How to use imported function to get current globals

2014-06-07 Thread 1989lzhh
Here is the code m1.py def f(): print globals() m2.py from m1 import f f()# how to get current module's globals? -- https://mail.python.org/mailman/listinfo/python-list

Re: How to use imported function to get current globals

2014-06-07 Thread Ian Kelly
On Sat, Jun 7, 2014 at 11:40 AM, 1989lzhh 1989l...@gmail.com wrote: Here is the code m1.py def f(): print globals() m2.py from m1 import f f()# how to get current module's globals? Evaluate globals() in the current module and pass the resulting dict in as a parameter: # m1.py def

Re: How to use imported function to get current globals

2014-06-07 Thread Chris Angelico
On Sun, Jun 8, 2014 at 3:40 AM, 1989lzhh 1989l...@gmail.com wrote: Here is the code m1.py def f(): print globals() m2.py from m1 import f f()# how to get current module's globals? As Ian said, you almost certainly do not want to do this. But if you have a solid use-case that involves

Re: How to use imported function to get current globals

2014-06-07 Thread Ned Batchelder
On 6/7/14 1:40 PM, 1989lzhh wrote: Here is the code m1.py def f(): print globals() m2.py from m1 import f f()# how to get current module's globals? Looking at the code you have posted in your two messages so far, it seems like you are building something very interesting and ambitious.

Re: How to use imported function to get current globals

2014-06-07 Thread 1989lzhh
发自我的 iPhone 在 Jun 8, 2014,4:52,Chris Angelico ros...@gmail.com 写道: On Sun, Jun 8, 2014 at 3:40 AM, 1989lzhh 1989l...@gmail.com wrote: Here is the code m1.py def f(): print globals() m2.py from m1 import f f()# how to get current module's globals? As Ian said, you almost

Re: How to use imported function to get current globals

2014-06-07 Thread Chris Angelico
On Sun, Jun 8, 2014 at 10:28 AM, 1989lzhh 1989l...@gmail.com wrote: 发自我的 iPhone 在 Jun 8, 2014,4:52,Chris Angelico ros...@gmail.com 写道: On Sun, Jun 8, 2014 at 3:40 AM, 1989lzhh 1989l...@gmail.com wrote: Here is the code m1.py def f(): print globals() m2.py from m1 import f f()#

Re: How to use imported function to get current globals

2014-06-07 Thread 1989lzhh
thanks all you guys. I have find the solution which is quite simple by using sys._frame(1).f_locals in function to get the caller's scope The following is my user case: I am writing a tool to translate python code to cython code then compiled using decorate. jit, build=make(mymodule) #jit