[sage-support] Re: Importing a Python module

2010-07-23 Thread KvS
On Jul 21, 2:34 am, Mike Hansen mhan...@gmail.com wrote:
 On Tue, Jul 20, 2010 at 9:27 AM, KvS keesvansch...@gmail.com wrote:
  Thanks for the quick reply. I tried putting from sage.all import *

 Could you post the code tohttp://sage.pastebin.com.  It is better to
 avoid using import * and explicitly list the things that you want to
 import.  That way you know what objects are coming from where.

 --Mike

Hi Mike,

the fact that you didn't yet report back, does that mean it is not
easily solved?

Thanks, Kees

-- 
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


[sage-support] Re: Importing a Python module

2010-07-20 Thread KvS
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


Re: [sage-support] Re: Importing a Python module

2010-07-20 Thread Mike Hansen
On Tue, Jul 20, 2010 at 9:27 AM, KvS keesvansch...@gmail.com wrote:
 Thanks for the quick reply. I tried putting from sage.all import *

Could you post the code to http://sage.pastebin.com .  It is better to
avoid using import * and explicitly list the things that you want to
import.  That way you know what objects are coming from where.

--Mike

-- 
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


[sage-support] Re: Importing a Python module

2010-07-20 Thread KvS
On Jul 21, 2:34 am, Mike Hansen mhan...@gmail.com wrote:
 On Tue, Jul 20, 2010 at 9:27 AM, KvS keesvansch...@gmail.com wrote:
  Thanks for the quick reply. I tried putting from sage.all import *

 Could you post the code tohttp://sage.pastebin.com.  It is better to
 avoid using import * and explicitly list the things that you want to
 import.  That way you know what objects are coming from where.

 --Mike

Cheers. Sure I understand 'import *' shouldn't be used unless ..., but
in this case it seems the right thing to do, a.o. since you otherwise
you have to keep on altering the importing if you use a new function
no? Here is the code from the Pyhton module (stripped down to only the
function that causes the problem, also with this stripped down version
the problem is the same for me): http://sage.pastebin.com/nH6iYiD4.

-- 
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


[sage-support] Re: Importing a Python module

2010-07-20 Thread KvS
On Jul 21, 2:34 am, Mike Hansen mhan...@gmail.com wrote:
 On Tue, Jul 20, 2010 at 9:27 AM, KvS keesvansch...@gmail.com wrote:
  Thanks for the quick reply. I tried putting from sage.all import *

 Could you post the code tohttp://sage.pastebin.com.  It is better to
 avoid using import * and explicitly list the things that you want to
 import.  That way you know what objects are coming from where.

 --Mike

Oh, and for completeness: this is the code from the notebook:

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

from Goran_optStoppLegendre1_tmp import *

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

-- 
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