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.Wed, 19 Dec 2018 22:46:32 +0100How to create a "sage program" with command line inputhttps://ask.sagemath.org/question/44708/how-to-create-a-sage-program-with-command-line-input/I am completely new to Sage and Pyhton, so this is probably a very trivial question, but I am not able to find any answer. I have a file script.sage
N=10
sage_command1
sage_command2
sage_command3
print(result)
I use this script via `sage script.sage` and it does what I want. How can I modify this so that I can pass the variable `N` in the command line? Something like `sage script.sage 10` and then it prints the result.
Thank you!Tue, 18 Dec 2018 23:35:35 +0100https://ask.sagemath.org/question/44708/how-to-create-a-sage-program-with-command-line-input/Answer by John Palmieri for <p>I am completely new to Sage and Pyhton, so this is probably a very trivial question, but I am not able to find any answer. I have a file script.sage</p>
<pre><code>N=10
sage_command1
sage_command2
sage_command3
print(result)
</code></pre>
<p>I use this script via <code>sage script.sage</code> and it does what I want. How can I modify this so that I can pass the variable <code>N</code> in the command line? Something like <code>sage script.sage 10</code> and then it prints the result.</p>
<p>Thank you!</p>
https://ask.sagemath.org/question/44708/how-to-create-a-sage-program-with-command-line-input/?answer=44714#post-id-44714You can start here: https://docs.python.org/3/library/sys.html#sys.argv and https://www.tutorialspoint.com/python/python_command_line_arguments.htm
Briefly: `N = sys.argv[1]` should work.Wed, 19 Dec 2018 22:46:32 +0100https://ask.sagemath.org/question/44708/how-to-create-a-sage-program-with-command-line-input/?answer=44714#post-id-44714