Ask Your Question
0

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

asked 2016-02-06 21:12:15 +0100

jmarcellopereira gravatar image

updated 2016-02-06 21:16:03 +0100

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-09 04:10:22 +0100

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-07 00:03:59 +0100

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 15:26:07 +0100 )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-09 04:10:44 +0100 )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 21:12:15 +0100

Seen: 1,526 times

Last updated: Feb 18 '16