Changes between Version 25 and Version 26 of DevelopingNewTools
- Timestamp:
- 12/14/06 09:33:38 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DevelopingNewTools
v25 v26 38 38 s = u'Some string' 39 39 }}} 40 * Only pass 8-bit ASCII strings to the {{{exec}}} statement. {{{exec}}} does seem to accept Unicode but I'm not sure its a good idea, since Python says the interpreter is supposed to assume ASCII encoding if no encoding is explicitly specified.41 40 42 41 * Enclose all string literals that will be viewed by the user in a call to the _ function. This function is the hook into Python's translation system, which is based on the GNU gettext utility. (For more information, look up the {{{gettext}}} module in Python's documentation.) If you have any doubt about whether the user will view a given string, assume that it will be and enclose it in the _ function. If you are wrong, the only cost is that we will needlessly localize the string to other languages. 53 52 * XML is typically encoded in UTF-8. But XML allows alternate encodings, which may be specified in the XML header. In any case, your Python code should use one of the standard XML modules, such as {{{xml.dom}}} or {{{xml.sax}}}, to manipulate XML. 54 53 * Text files are encoded in various encodings, depending on the operating system. On English versions of the Windows operating system, they are usually 8-bit strings using the Latin-1 encoding. But even the notepad.exe program can now save files in alternative encodings, such as UTF-8 or Unicode-LE. If your tool processes text files, consider allowing the caller to specify an encoding or at least document the encodings you support. See [http://www.amk.ca/python/howto/unicode Unicode HOWTO] for an example of using the {{{codecs.open}}} function to read and write text files in specific encodings. 54 * Only pass 8-bit ASCII strings to the Python {{{exec}}} statement. {{{exec}}} does seem to accept Unicode but I'm not sure its a good idea, since Python says the interpreter is supposed to assume ASCII encoding if no encoding is explicitly specified. 55 55 56 56
