Ask Your Question
0

Loading a file unter Windows

asked 5 years ago

annegret gravatar image

I am a complete beginner in SageMath. I would like to write a small program in a seperate file and load this into sage. In the German user manual I found the syntax load("beispiel.sage"). But this cannot work, since the program does not know where to look for the file. So I have to tell it the complete path. I tried a lot of different commands, like e.g. load("C:\Users\annegret\Documents\beispiel.sage") or load(`C:\Users\annegret\Documents\beispiel.sage´). I am working unter Windows with the console.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

Sébastien gravatar image

updated 5 years ago

If using a local path, it has to be relative to the present working directory which you can obtain by typing pwd in the sage command line.

sage: pwd

Otherwise, I cannot confirm since I do not have access to a Windows machine, but I would suggest to try to use double backlashes or use raw strings with the small r in front:

sage: load("C:\\Users\\annegret\\Documents\\beispiel.sage")

or

sage: load(r"C:\Users\annegret\Documents\beispiel.sage")

because '\n', '\b', '\U' , '\t' are meant to be characters with special meanings like new lines, tabulations, etc. See this page on Litterals from Python doc for details.

Preview: (hide)
link

Comments

Thank you. That was helpful. I am now using the relative path to the sage working directory and that works. I use e.g. load("./Documents/test.sage").

annegret gravatar imageannegret ( 5 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

Stats

Asked: 5 years ago

Seen: 283 times

Last updated: Mar 25 '20