getting user imput in Python scripts
How can I write a script that will get user input when the script runs. I am talking about the sage notebook() here rather than the cli sage.
How can I write a script that will get user input when the script runs. I am talking about the sage notebook() here rather than the cli sage.
This is not really a Sage question. Anyway, use input
in python.
In [1]: a = input('Enter number: ')
Enter number: 10
In [2]: a
Out[2]: 10
In [3]: a = input('Enter string')
Enter string: 'test'
In [4]: a
Out[4]: 'test'
In the sage notebook you can use the @interact
decorator. See examples of it here.
The OP used `guess = int(raw_input('Take a guess: '))` (unsuccessfully) in his Stackoverflow question - would this work similarly? In particular, he's talking about using it in a *script*, not interactively (as far as I can tell). (http://stackoverflow.com/questions/15085251/getting-user-input-in-sage-python)
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2013-02-26 04:09:24 +0100
Seen: 2,230 times
Last updated: Feb 26 '13