Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

import sage packages in python

An easy way to use sage in python files is demonstrated in the Sage Tutorial. #!/usr/bin/env sage -python

import sys
from sage.all import *

if len(sys.argv) != 2:
    print "Usage: %s <n>"%sys.argv[0]
    print "Outputs the prime factorization of n."
    sys.exit(1)

print factor(sage_eval(sys.argv[1]))

Well, what if I don't want to import all of sage as shown above using:

from sage.all import *

Instead of this command above, I just want to import the following:

  1. Matrix -> type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'
  2. vector -> type 'sage.modules.vector_integer_dense.Vector_integer_dense'
  3. ZZ -> type 'sage.rings.integer_ring.IntegerRing_class'
  4. MixedIntegerLinearProgram -> type 'sage.numerical.mip.MixedIntegerLinearProgram'

So I should be able to write something like this in python

from sage.library.package.for.Matrix import *
from sage.library.package.for.vector import *
from sage.library.package.for.ZZ import *
from sage.library.package.for.MixedIntegerLinearProgram import *

I just don't know what they are. Any help is appreciated.

Thanks.

click to hide/show revision 2
No.2 Revision

import sage packages in python

An easy way to use sage in python files is demonstrated in the Sage Tutorial. #!/usr/bin/env sage -python.

#!/usr/bin/env sage -python

import sys
from sage.all import *

if len(sys.argv) != 2:
    print "Usage: %s <n>"%sys.argv[0]
    print "Outputs the prime factorization of n."
    sys.exit(1)

print factor(sage_eval(sys.argv[1]))

Well, what if I don't want to import all of sage as shown above using:

from sage.all import *

Instead of this command above, I just want to import the following:

  1. Matrix -> type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'
  2. vector -> type 'sage.modules.vector_integer_dense.Vector_integer_dense'
  3. ZZ -> type 'sage.rings.integer_ring.IntegerRing_class'
  4. MixedIntegerLinearProgram -> type 'sage.numerical.mip.MixedIntegerLinearProgram'

So I should be able to write something like this in python

from sage.library.package.for.Matrix import *
from sage.library.package.for.vector import *
from sage.library.package.for.ZZ import *
from sage.library.package.for.MixedIntegerLinearProgram import *

I just don't know what they are. Any help is appreciated.

Thanks.