First time here? Check out the FAQ!

Ask Your Question
1

Sharing code between worksheets (Windows)

asked 13 years ago

G-Sage gravatar image

Dear all

I recently read the following question and answers:

http://ask.sagemath.org/question/732/how-can-i-share-code-between-worksheets

The problem is, I use Windows. This answer does not really work for me, though it would be wonderful if I could put all of my custom functions in one worksheet and then reference those in any other worksheet I use. I don't even know where to begin. For one, I don't even have access to the Shell (pardon me if I don't really talk about things properly because I don't really know what I'm talking about). When I start up my Virtual machine for Sage 4.7 in Virtual Box, it opens up a DOS looking window (the Shell, right?) and says a bunch of stuff and when it stops moving, I open up my browser and do http:\localhost:8000 or whatever. If I try to do anything in the Shell, nothing happens. I type stuff, I see my typing. I hit enter, it just does moves the cursor to the next line. Nothing else ever happens. So, all I have access to is the Notebook stuff. And, I've looked all over in that and I don't really know how to save a worksheet as a .py or .sage or whatever other file types are required. I've tried to look around my virtual machine and I have no idea how to access the various directories. I could probably figure it out if the Shell worked, but it doesn't.

Can any one help me at all?

Thanks!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 13 years ago

Volker Braun gravatar image

updated 13 years ago

A very simple way of adding a fixed piece of code to the worksheet is to put it on a web server somewhere and then add the line

load('http://my.webserver.com/path/to/code.py')

at the beginning of the worksheet. Evaluating that will load the code from the web server.

If you are using the VirtualBox image then the notebook server is running on the console. If you want to go back to the Sage command line, you have to press Ctrl-C first to stop the notebook server. This will drop you to the unix shell, where you can start the sage command line. That is, after pressing Ctrl-C you see the [sage@sage sage]$ prompt, type sage and press return. Then you can directly work with the Sage command line. Using the unix shell, you can also poke around in the virtual machine.

Using the VirtualBox appliance, you could share a folder on your host computer. In VirtualBox, click on Shared Folders and pick a folder. Give it the name Shared, say. Then, on the unix command line in the virtual machine, type

sudo mount -t vboxsf Shared /mnt

The password is sage. This will make the shared folder appear at /mntinside the virtual machine. Then you can follow http://ask.sagemath.org/question/732/... and, for example, use

%auto
attach('/mnt/mycode.py')
Preview: (hide)
link

Comments

@Volker Okay, I haven't tried all this out, but it seems like it should be very helpful. Thanks. But, one more thing. How do I save my sage code into a file with the name mycode.py? Can I do something as simple as open a .txt and copy and paste the code from one of my Sage notebooks, and then save the file as mycode.py? Is there anything special about a .py file where this wouldn't work?

G-Sage gravatar imageG-Sage ( 13 years ago )
1

Yes, that should work. A .py file is just a text file containing code.

Jason Grout gravatar imageJason Grout ( 13 years ago )

Alright, I tried it and it worked so easily. Thanks! This is really great!

G-Sage gravatar imageG-Sage ( 13 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: 13 years ago

Seen: 1,221 times

Last updated: Sep 13 '11