ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 26 Mar 2020 14:32:59 +0100Loading a file unter Windowshttps://ask.sagemath.org/question/50358/loading-a-file-unter-windows/ 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.Wed, 25 Mar 2020 17:53:35 +0100https://ask.sagemath.org/question/50358/loading-a-file-unter-windows/Answer by Sébastien for <p>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.</p>
https://ask.sagemath.org/question/50358/loading-a-file-unter-windows/?answer=50361#post-id-50361If 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](https://docs.python.org/3/reference/lexical_analysis.html#literals) from Python doc for details.Wed, 25 Mar 2020 21:56:16 +0100https://ask.sagemath.org/question/50358/loading-a-file-unter-windows/?answer=50361#post-id-50361Comment by annegret for <p>If using a local path, it has to be relative to the present working directory which you can obtain by typing <code>pwd</code> in the sage command line. </p>
<pre><code>sage: pwd
</code></pre>
<p>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:</p>
<pre><code>sage: load("C:\\Users\\annegret\\Documents\\beispiel.sage")
</code></pre>
<p>or</p>
<pre><code>sage: load(r"C:\Users\annegret\Documents\beispiel.sage")
</code></pre>
<p>because <code>'\n'</code>, <code>'\b'</code>, <code>'\U'</code> , <code>'\t'</code> are meant to be characters with special meanings like new lines, tabulations, etc. See <a href="https://docs.python.org/3/reference/lexical_analysis.html#literals">this page on Litterals</a> from Python doc for details.</p>
https://ask.sagemath.org/question/50358/loading-a-file-unter-windows/?comment=50370#post-id-50370Thank 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").Thu, 26 Mar 2020 14:32:59 +0100https://ask.sagemath.org/question/50358/loading-a-file-unter-windows/?comment=50370#post-id-50370