Py3.3 unicode literal and input()

Ulrich Eckhardt ulrich.eckhardt at dominolaser.com
Mon Jun 18 10:46:20 EDT 2012


Am 18.06.2012 16:00, schrieb jmfauth:
> A string is a string, a "piece of text", period.

No. There are different representations for the same piece of text even
in the context of just Python. b'fou', u'fou', 'fou' are three different
source code representations, resulting in two different runtime
representation and they all represent the same text: fou.


> I do not see why a unicode literal and an (well, I do not
> know how the call it) a "normal class <str>" should behave
> differently in code source or as an answer to an input().

input() retrieves a string from a user, not from a programmer that can
be expected to know the difference between b'\x81' and u'\u20ac'.


> Should a user write two derived functions?
> 
> input_for_entering_text()
> and
> input_if_you_are_entering_a_text_as_litteral()

With "user" above, I guess you mean "Python programmer". In that case,
the answer is yes. Although asking the user of your program to learn
about Python's string literal formatting options is a bit much.


> Side effect from the unicode litteral reintroduction.
> I do not mind about this, but I expect it does
> work logically and correctly. And it does not.

Yes it does. The user enters something. Python receives this and
provides it as string. You as a programmer are now supposed to
interpret, parse etc this string according to your program logic.


BTW: Just in case there is a language (native language, not programming
language) problem, don't hesitate to write in your native language, too.
Chances are good that someone here understands you.

Good luck!

Uli




More information about the Python-list mailing list