Ask Your Question
1

Importing a sage library???

asked 2012-03-23 09:27:13 +0100

pvl gravatar image

How do I import a sage library? Mine is called functions.sage. But when I import - python says it doesn't know it. I tried:

__import__('functions.sage')

and also:

import imp
imp.load_source('fun', 'functions.sage')

None works!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-03-23 09:47:59 +0100

pvl gravatar image

updated 2012-03-26 08:01:25 +0100

Summary: in order to load a function from a .sage lib in sage - one has to parse the .sage file first - it will make a .py file - and then import the .py file.

Example:

import os
os.system(os.curdir + os.sep + 'functions.sage')
from functions import states

This way the .sage code got executed in sage - not in python.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-03-23 09:27:13 +0100

Seen: 584 times

Last updated: Mar 26 '12