Forum Archive

Input and quotes

rudijuri

Hello everyone,
excuse my ignorance, but I do not understand why Pythonista returns error when, for example, the code is like this:

text = input ('enter the text : ')
print (text)

If the string typed by the user is not enclosed in quotation marks, Pyhonista says that the string itself is not defined. Why?

Thanks a lot, and excuse me again.

JR

ccc

In Python3, input() is the way to go but in Python2 (like Pythonista) use raw_input() instead.

rudijuri

Ops, thank you very much.
JR

Gerzer

I just thought of something that might actually work (for once). There must be many more Python beginners than who we see on the forums, and lots of them probably don't know how to work with Python 2, only Python 3. What if, to get around Apple's dynamic linking restrictions, @omz added a way to (optionally) automatically use lib3to2 to convert simple Python 3 code to Python 2 code when the run button is pressed but before the actual execution? I know the 3to2 tool doesn't convert everything, but if you are writing Python 3 code 3to2 can't handle, you most likely are experienced enough to understand the differences between Python 2 and Python 3, right? The option could come with a warning about advanced code just in case, though. Just an idea. :)

rudijuri

@Gerzer Thanks

ccc
import six  # already works in Pythonista

http://pythonhosted.org/six is another Python 2 and 3 Compatibility Library

dgelessus

@ccc

http://pythonhosted.org/six is the Python 2 and 3 Compatibility Library

FTFY ;)

ccc

Yeah but... https://docs.python.org/2/library/2to3.html Is part of the Python Standard Library and six is not.

dgelessus

The two libraries have entirely different purposes though. (lib)2to3 is used to convert Python 2 code to Python 3, while six is a library that makes it easy to write Python code that runs on multiple Python versions without modification.