Re: Why I need to declare import as global in function

2005-11-30 Thread Fredrik Lundh
Dennis Lee Bieber wrote: > > But the solutions already proposed seems to work file for my sample > > program. I will try on my project soon :) > > Looking at the documentation for "execfile", I can see /how/ the > problem occurs -- but can't determine if this can be considered > "expected". > > -=

Re: Why I need to declare import as global in function

2005-11-30 Thread Rick Wotnaz
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > On 30 Nov 2005 00:58:45 -0800, [EMAIL PROTECTED] > declaimed the following in comp.lang.python: > >> yes I have imported math in the file I want to use it. But the >> imported module "math" is not visible in function withou

Re: Why I need to declare import as global in function

2005-11-30 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > I think I understand my problem, but first the sample code extracted to > my project. > > Rq : it's an automatic run of unitary test, the names of unitary test > are parameter of main program "imported" file via the "execfile" > function (an usage of "import" instead ma

Re: Why I need to declare import as global in function

2005-11-30 Thread didier . doussaud
sample and solution posted in another branch of this thread -- http://mail.python.org/mailman/listinfo/python-list

Re: Why I need to declare import as global in function

2005-11-30 Thread didier . doussaud
yes I have imported math in the file I want to use it. But the imported module "math" is not visible in function without a global instruction. But the solutions already proposed seems to work file for my sample program. I will try on my project soon :) -- http://mail.python.org/mailman/listinfo/

Re: Why I need to declare import as global in function

2005-11-30 Thread didier . doussaud
lot's of solutions proposed in the discussion works fine : file run.py : def run_ut( test ) : # to have the problem the execfile MUST be in a function # execfile( test ) # ERROR execfile( test, globals() ) # OK exec "import ut_00" # OK exec file(test).read() #

Re: Why I need to declare import as global in function

2005-11-30 Thread didier . doussaud
I think I understand my problem, but first the sample code extracted to my project. Rq : it's an automatic run of unitary test, the names of unitary test are parameter of main program "imported" file via the "execfile" function (an usage of "import" instead may be a solution) : file run.py :

Re: Why I need to declare import as global in function

2005-11-29 Thread didier . doussaud
You're right, the problem is around the usage of "execfile". But I have still difficulties to get a simple sample and have no enough time to work on it until end of week. I will post if I resolve my problem or if I can get a simple sample. -- http://mail.python.org/mailman/listinfo/python-

Re: Why I need to declare import as global in function

2005-11-29 Thread Fredrik Lundh
Duncan Booth wrote: > That is unlikely to help. The execfile target seems to have been > TU_05_010.py, but the file which cannot access math is TU_05_tools.py > accessed by a normal import, so adding some globals to the execfile call > won't really do anything useful. > > Isn't it fun trying to gu

Re: Why I need to declare import as global in function

2005-11-29 Thread Peter Otten
Duncan Booth wrote: > Isn't it fun trying to guess the problem in the absence of the code? What other reason could there be to forego the sane approach -- stick 'import math' everywhere it might belong? Those exec/execfile() peculiarities are so much more interesting ;-) Peter -- http://mail.

Re: Why I need to declare import as global in function

2005-11-29 Thread Duncan Booth
Peter Otten wrote: >> Traceback (most recent call last): >>File "../tu.py", line 21, in run_tu >> execfile( filename ) >>File "TU_05_010.py", line 8, in ? >> import TU_05_tools >>File "./TU_05_tools.py", line 4, in ? >> f() >>File "./

Re: Why I need to declare import as global in function

2005-11-29 Thread Peter Otten
[EMAIL PROTECTED] wrote: > the error message : > > EXCEPTION RAISED:: > > Traceback (most recent call last): >File "../tu.py", line 21, in run_tu > execfile( filename ) >File "TU_05_010.py", line 8, in ? > import TU_05_tools >File "./TU_05_tools.py"

Re: Why I need to declare import as global in function

2005-11-29 Thread Duncan Booth
wrote: > I have remarq that this problem is raised when I execute code in an > imported module (during importation) > > I think I will be able to isolate it and have a simple sample soon > Meanwhile, try adding: import math to the top of TU_05_tools.py. -- http://mail.python.org/mail

Re: Why I need to declare import as global in function

2005-11-29 Thread didier . doussaud
the error message : EXCEPTION RAISED:: Traceback (most recent call last): File "../tu.py", line 21, in run_tu execfile( filename ) File "TU_05_010.py", line 8, in ? import TU_05_tools File "./TU_05_tools.py", line 4, in ? f() File "./TU_

Re: Why I need to declare import as global in function

2005-11-28 Thread Tim N. van der Leeuw
Sounds like something, either in your program, in another lib you imported, or perhaps some extension you recently installed (and which automatically starts), overrides 'import' (replaces it with it's own version) -- and forgets to add the imported modules properly to the globlals? Or something, so

Re: Why I need to declare import as global in function

2005-11-28 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I have a stange side effect in my project : > > in my project I need to write "gobal" to use global symbol : > > ... > import math > ... > def f() : >global math # necessary ?? else next line generate an error > message ? what error message? >print mat

Why I need to declare import as global in function

2005-11-28 Thread didier . doussaud
I have a stange side effect in my project : in my project I need to write "gobal" to use global symbol : ... import math ... def f() : global math # necessary ?? else next line generate an error message ? print math.pi (the problem is for all global module symbol) I have certainl