Dear all,

I was trying to find a way to import code form a python file to my
notebook (the reason is mainly to save long code in a different place
as just a plain text file, and also to be able to work on the code in
a Python editor). However, if I copy-paste working code from a
notebook to an editor, save it as a .py file and then import it into
the notebook things go wrong. In particular Sage complains about the
sgn() function.

This is the code from my notebook:

import sys
pth='/home/kees/SAGE_Python_modules/Goran'
if not pth in sys.path:
    sys.path.append(pth)

from Goran_optStoppLegendre1 import *

G(x)=x^2-4; a=-3; b=3
print signScheduleOfFunction(G,a,b,10)

where signScheduleOfFunction is a class that works fine when the code
is in the notebook itself, but importing it this way yields:

Traceback (most recent call last):
  File "", line 1, in <module>

  File "/tmp/tmpUx0ehw/___code___.py", line 23, in <module>
    exec compile(u'print signScheduleOfFunction(G,a,b,_sage_const_10 )
  File "", line 1, in <module>

  File "/home/kees/SAGE_Python_modules/Goran/
Goran_optStoppLegendre1.py", line 195, in __init__
 
self.zerosList=findZerosOnInterval(func,a,b,maxDiff=10^(-4),guessIntervals=intVals,showProgress=False)
  File "/home/kees/SAGE_Python_modules/Goran/
Goran_optStoppLegendre1.py", line 33, in findZerosOnInterval
 
res2=findZerosOnInterval(func,interval[0],interval[1],maxDiff,guessIntervals=None,showProgress=False)
  File "/home/kees/SAGE_Python_modules/Goran/
Goran_optStoppLegendre1.py", line 42, in findZerosOnInterval
    signFunc1=sgn(func(a)); signFunc2=sgn(func(b))
NameError: global name 'sgn' is not defined

So I guess my problem is that I don't understand the namespaces
involved somehow, since sgn() lives somewhere in a Sage namespace and
importing doesn't place the code in the right name space or something?
Does anybody have a hint how I may do things so such an import will
work?

Many thanks, Kees

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to