pyrex question

1 view
Skip to first unread message

mb

unread,
Feb 9, 2008, 10:58:02 PM2/9/08
to sage-forum
Hello,

I have a basic question about using pyrex from a sage script. Suppose
I have a file "test.pyx":

def f(int n):
return n

Then from the sage interpreter I can use it:

sage: load "test.pyx"
Compiling test.pyx...
sage: f(3)
3

But I'd like to use it from a script, e.g. "main.sage":

load "test.pyx"
print f(3)

Then I get:

mb@hvar:~$ sage main.sage
Traceback (most recent call last):
File "main.py", line 4, in <module>
print f(Integer(3))
NameError: name 'f' is not defined

I tried modifying test.pyx by inserting the word "public" after "def"
but it didn't help. Is there any way of doing this?

Mladen

William Stein

unread,
Feb 10, 2008, 1:36:03 AM2/10/08
to sage-...@googlegroups.com

This is not implemented yet, though it will be implemented.
There is a partial workaround that might be enough for you now.

(1) Create test.pyx and main.sage as follows:
teragon:tmp was$ more test.pyx


def f(int n):
return n

teragon:tmp was$ more main.sage
print f(3)

(2) You can use main.sage if you do the following:


sage: load test.pyx
Compiling test.pyx...

sage: load main.sage
3

This is now trac ticket #2137:

http://trac.sagemath.org/sage_trac/ticket/2137

William

Reply all
Reply to author
Forward
0 new messages