I'm running Spyder 3.1.2 (Python 2.7.13). I have the Automatically load 
Pylab and NumPy modules 
<http://www.southampton.ac.uk/%7Efangohr/blog/spyder-the-python-ide.html#no-convenience-imports-in-ipython-console>
 
setting activated. As such I can call commands like zeros(5) in the IPython 
Console, instead of having to explicitly import numpy and specify 
np.zeros(5).

In [12]: zeros(5)Out[12]: array([ 0.,  0.,  0.,  0.,  0.])
>
>
The problem is when I call a function from a different python file that 
makes use of one of these automatically loaded terms.

If I create a function UseZeros() in the Test1.py file

"""
> filename: Test1.py
> """
> def UseZeros():
>     return zeros(4)
>
>
 and try to call it from a second file Test2.py

"""
> filename: Test2.py
> """
> import Test1
>
> testArr1 = zeros(5)
> testArr2 = Test1.UseZeros()
>
>
The first line testArr1 = zeros(5) runs fine, but then I get an error on 
the second line:

File "C:/Users/Gareth/Test2.py", line 8, in testArr2 = Test1.UseZeros()
>
> File "Test1.py", line 7, in UseZeros return zeros(4)
>
> NameError: global name 'zeros' is not defined
>
 I don't know if this is a bug, or if I'm doing something wrong.

This is just a simple example of the problem I'm having. A colleague is 
working on a project that makes use of many imported functions. I want to 
call some functions from his files, but I keep getting these errors. The 
only way to solve it is to explicitly make these definitions in his files. 
But I want to be able to call his functions without changing his code.

I'd appreciate any help.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.

Reply via email to