I'm fairly new to Python. I've just started working with PythonforIOS 3.4, and am having trouble with input(). I think it's a bug in the IOS implementation but want to be sure I understand things correctly.
If the user just hits enter (a null response) a KeyboardInterrupt exception is raised instead of simply returning a null string ('') as the result which is what I had expected. Is this correct? In Python 2 raw_input does return '' I think. I had understood that in Python 3 input replaced raw_input.
Try some testing:
try:
s = input('enter string: ')
except KeyboardInterrupt:
print 'Error raised'
If the 'Error raised' message prints up, which I'm sure it will from what your question says, then it is likely a bug in iOS. From what I know, the input function in Python 3 can take an empty string, though I'm not for sure as I don't yet work in Python 3.
I would suggest for now, putting a try/except case in a while loop to prevent blank input from occurring like:
while True:
try:
s = input('enter string: ')
break
except KeyboardInterrupt:
continue
And report the bug to Apple. As for "I had understood that in Python 3 input replaced raw_input", you are correct there, input() is the only standard way to get user input.
Also, the only way that people can help you fully is if you post your code that you are having problems with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With