First time here? Check out the FAQ!

Ask Your Question
1

Importing a sage library???

asked 13 years ago

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!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 13 years ago

pvl gravatar image

updated 13 years ago

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.

Preview: (hide)
link

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: 13 years ago

Seen: 629 times

Last updated: Mar 26 '12