wxPython and Croatian characters

"Martin v. Löwis" martin at v.loewis.de
Mon Feb 16 17:49:18 EST 2009


>> Unless you are using python 3.0 (which I doubt, afaik no wx available), 
>> your above coding declaration is useless for the shown piece of code, as 
>> it only applies to unicode literals, which are written with a preceding u.
>>
> 
> No.  The coding declaration does nothing to unicode literals.  It only
> affects how the python's source code parser reads the the source code.

And, as such, it *only* affects Unicode literals, really nothing else
(except for error checking).

In 2.x, non-ASCII characters can occur only in these places:
- comments. no effect on semantics of script
- string literals. run-time representation is equal to on-disk
  representation, so no effect.
- unicode literals. run-time representation is 2-byte or 4-byte UCS,
  so parser needs to decode on-disk representation to in-memory
  representation. This is the *only* place where the declared encoding
  matters.

> Without it, your source code will be parsed (or is it lexed?) by python
> as an ascii document.  So if your document is UTF-8, it will choke as
> soon as it reaches a non ascii character. 

So yes, it does an additional error check also. But the main reason for
the encoding declaration (besides sanity for text editors also) is
Unicode literals (in 3.x, also relevant for identifiers)

Regards,
Martin



More information about the Python-list mailing list