Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Pythonista Problem
-
Hi,
I'm very new to python. Sorry if this is a dumb question, but if i run a very simple program in the console asking for user input, the input prints immediately after the question, even if i don't ask for that in the program.
If my program is just Input('What is your name?') the console will print the question, but when i input a name it will add that name onto the end of the question immediately.
If i do a slightly longer program: x = input('What is your name?')
print('Hello ' + x)the screen looks like this after input: What is your name?stuart
Hello StuartWhy is this?
-
@looperboy, this is by design. As a result, the screen looks like you would have typed the text in that location.
If you do not want it, you can temporarily redirect stdout:
import io, contextlib print('Enter something:') with contextlib.redirect_stdout(io.StringIO()): t = input('') print(f'You entered {t}')
-
@looperboy easier, sorry @mikael , for a new Python user, try to run this
import console x = console.input_alert('What is your name?') print('Hello '+x)
-
Thank you!
-
@looperboy But, is it what you want?
-
It helps to know the input is being printed by design. Is this just for development purposes, so’s you know the code is receiving the input?
-
@looperboy, you can use Pythonista to learn Python, and indeed I did something like that.
But if you follow some online Python courses, you will run across some differences in how Python runs in a terminal on a laptop and how it runs on Pythonista.
input
behaviour is one such difference, as it perhaps makes more sense in the terminal, where input and output are mixed and it would look like this:>>> name = input('What is your name? ') What is your name? Name Name >>> name 'Name Name'
That is, the first ”Name Name” appears as you type it, character by character, so that you see what you are typing, whereas in Pythonista, you type it in the console prompt, and then it ”jumps” to the ”right place” when you press enter.
This is by design, and similar to how many other apps work, but something to be aware of.
For a new Python learner, there are other pitfalls as well, like the language version differences between Python 3.6, which Pythonista uses, and whatever version is used by the tutorial you are following.
Would be good to know if your goal is ”to learn Python” or ”to just get something running in Python on iOS”. For the latter, the
console
module suggested by @cvp is a great option, but good to be aware that it is Pythonista-only. -
Thanks, Mikael. You are correct in noticing I've been following some online courses, as well as reading some books, and have encountered differences in how Python runs on Pythonista.
The tutorials I have been following do use 3.6, mainly, and my goal is to learn python rather than run anything on iOS. I got Pythonista as a convenient way to practice coding rather than because it was related to iOS. Just as a way to tinker with code wherever I am.