First time here? Check out the FAQ!

Ask Your Question
0

How to import the file "function.py" to worksheet sage? sagemath loaded by virtual machine (VirtualBox)

asked 9 years ago

jmarcellopereira gravatar image

updated 9 years ago

i want to import a file function called "function.py" to my Worksheet. How to do?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 9 years ago

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi

I solved the problem I created the file function fiboR_SG.py below

def fiboR_SG(n) :
   if n < 2:
      return n
   else:
      return fiboR_SG(n-1) + fiboR_SG(n-2)

upload fiboR_SG.py using "DATA" in Worksheet menu. In the "You may download fiboR_SG.py or create a link to this file in worksheet" select your worksheet. Back worksheet and use: import fiboR_SG ("no .py")

fiboR_SG. fiboR_SG(10)
55

OK :)

Preview: (hide)
link
1

answered 9 years ago

tmonteil gravatar image

Let me assume that you use jupyter notebook (the behaviour depends on the interface), you can do:

%attach /path/to/function.py

or (inlining the content)

%load /path/to/function.py
Preview: (hide)
link

Comments

Hello tmolteil

my files are on the local machine and the sagemath runs on the virtual machine. I tried that way, but only import virtual machine files, not the host machine.

jmarcellopereira gravatar imagejmarcellopereira ( 9 years ago )

Hi

I solved the problem I created the file function fiboR_SG.py below

def fiboR_SG(n):

if n < 2:

    return n

else:

    return fiboR_SG(n-1) + fiboR_SG(n-2)

upload fiboR_SG.py using "DATA" in Worksheet menu. In the "You may download fiboR_SG.py or create a link to this file in worksheet" select your worksheet. Back worksheet and use: import fiboR_SG ("no .py")

fiboR_SG. fiboR_SG(10)

55

OK :)

jmarcellopereira gravatar imagejmarcellopereira ( 9 years ago )

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 9 years ago

Seen: 1,556 times

Last updated: Feb 18 '16