Ask Your Question
0

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

asked 2016-02-06 14:12:15 -0500

jmarcellopereira gravatar image

updated 2016-02-06 14:16:03 -0500

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-02-08 21:10:22 -0500

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 :)

edit flag offensive delete link more
1

answered 2016-02-06 17:03:59 -0500

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
edit flag offensive delete link more

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 ( 2016-02-07 08:26:07 -0500 )edit

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 ( 2016-02-08 21:10:44 -0500 )edit

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: 2016-02-06 14:12:15 -0500

Seen: 876 times

Last updated: Feb 18 '16