On Jul 21, 2:01 am, Mike Hansen <mhan...@gmail.com> wrote:
> On Tue, Jul 20, 2010 at 8:58 AM, KvS <keesvansch...@gmail.com> wrote:
> > 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?
>
> The globals defined when Sage starts up are from sage.all (or
> sage.all_cmdline or sage.all_notebook).
>
> So, in your module,  you could do "from sage.all import sgn" along
> with anything else you need.  You could also do "from sage.all import
> *".
>
> --Mike

Thanks for the quick reply. I tried putting "from sage.all import *"
on the first line of the python file to be imported. Now the importing
indeed works fine, but if I run the code it gets stuck in some
infinite/too deep recursion it seems. Below part of the output. Indeed
the function findZerosOnInterval() that occurs in the output is
recursively defined. But if I put the code from the python file in the
notebook again (literally copy-paste, did it again to double check) -
except for the "from sage.all import *" of course - the code does
terminate quickly and yields the expected output. I don't use any
fancy constructions, just plain functions and (old style) classes. Do
you have any idea what might be going on?


Output:

Exception RuntimeError: 'maximum recursion depth exceeded while
calling a Python object' in <type 'exceptions.TypeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded while
calling a Python object' in <type 'exceptions.TypeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded while
calling a Python object' in <type 'exceptions.TypeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded while
calling a Python object' in <type 'exceptions.TypeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded in
__subclasscheck__' in <type 'exceptions.TypeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded in
__subclasscheck__' in <type 'exceptions.TypeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded while
calling a Python object' in <type 'exceptions.GeneratorExit'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded while
calling a Python object' in <type 'exceptions.GeneratorExit'> ignored
Exception GeneratorExit in <generator object <genexpr> at 0xafcadec>
ignored
Exception RuntimeError: 'maximum recursion depth exceeded while
calling a Python object' in <type 'exceptions.TypeError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded while
calling a Python object' in <type 'exceptions.TypeError'> ignored
Traceback (most recent call last):
  File "", line 1, in <module>

  File "/tmp/tmp9jxEuQ/___code___.py", line 16, in <module>
    exec compile(u'print
signScheduleOfFunction(G,a,b,_sage_const_10 )' + '\n', '', 'single')
  File "", line 1, in <module>

  File "/home/kees/SAGE_Python_modules/Goran/
Goran_optStoppLegendre1.py", line 197, 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 35, 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 105, in findZerosOnInterval
    +findZerosOnInterval(func,zero
+maxDiff,b,maxDiff,guessIntervals=None,showProgress=showProgress))
  File "/home/kees/SAGE_Python_modules/Goran/
Goran_optStoppLegendre1.py", line 93, in findZerosOnInterval
    return
sorted(findZerosOnInterval(func,a,xMin,maxDiff,guessIntervals=None,showProgress=showProgress)
  File "/home/kees/SAGE_Python_modules/Goran/
Goran_optStoppLegendre1.py", line 105, in findZerosOnInterval
    +findZerosOnInterval(func,zero
+maxDiff,b,maxDiff,guessIntervals=None,showProgress=showProgress))
.
.
.
.
 File "/home/kees/SAGE_Python_modules/Goran/
Goran_optStoppLegendre1.py", line 105, in findZerosOnInterval
    +findZerosOnInterval(func,zero
+maxDiff,b,maxDiff,guessIntervals=None,showProgress=showProgress))
  File "/home/kees/SAGE_Python_modules/Goran/
Goran_optStoppLegendre1.py", line 44, in findZerosOnInterval
    signFunc1=sgn(func(a)); signFunc2=sgn(func(b))
  File "function.pyx", line 417, in
sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:
4336)
TypeError: cannot coerce arguments: object of type 'generator' has no
len()

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

Reply via email to