Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

asked 12 years ago

Steven gravatar image

How to use cython functions from other cython cells in notbook?

Hi, I'm currently using sage with the notebook interface. How can I define a function in a cython cell and use it in another cython cell? I understand I need to import the first cython module but the name changes after every evaluation. Also being able to do this directly from notebook (without writing a separate cython file) and from separate cells would be handy.

For example this works fine:

%cython
def test(int n):
    return 2*n

def test2(m):
    return test(m)

test2(3)

but this does not:

%cython
def test3(int m):
    return test(m)

Thank you :)

click to hide/show revision 2
No.2 Revision

How to use cython functions from other cython cells in notbook?

Hi, I'm currently using sage with the notebook interface. How can I define a function in a cython cell and use it in another cython cell? cell?

I understand I need to import the first cython module but the name changes after every evaluation. evaluation.

Also being able to do this directly from notebook (without writing a separate cython file) and from separate cells would be handy.

For example this works fine:

cell1:

%cython
def test(int n):
    return 2*n
 

cell 2:

def test2(m):
    return test(m)
 

cell 3:

test2(3)
5

but this does not:

cell 4:

%cython
def test3(int m):
    return test(m)
pyx:7:15: undeclared name not builtin: test

Thank you :)