"Fred L. Drake, Jr." wrote: > > M.-A. Lemburg writes: > > def encode(self,u): > > > > """ Return the Unicode object u encoded as Python string. > > This should accept an optional slice parameter, and use it in the > same way as .dump(). Ok. > > def dump(self,u,stream,slice=None): > ... > > def load(self,stream,length=None): > > Why not have something like .wrapFile(f) that returns a file-like > object with all the file methods implemented, and doing to "right > thing" regarding encoding/decoding? That way, the new file-like > object can be used directly with code that works with files and > doesn't care whether it uses 8-bit or unicode strings. See File Output of the latest version: File/Stream Output: ------------------- Since file.write(object) and most other stream writers use the 's#' argument parsing marker, the buffer interface implementation determines the encoding to use (see Buffer Interface). For explicit handling of Unicode using files, the unicodec module could provide stream wrappers which provide transparent encoding/decoding for any open stream (file-like object): import unicodec file = open('mytext.txt','rb') ufile = unicodec.stream(file,'utf-16') u = ufile.read() ... ufile.close() XXX unicodec.file(<filename>,<mode>,<encname>) could be provided as short-hand for unicodec.file(open(<filename>,<mode>),<encname>) which also assures that <mode> contains the 'b' character when needed. > > Codecs should raise an UnicodeError in case the conversion is > > not possible. > > I think that should be ValueError, or UnicodeError should be a > subclass of ValueError. Ok. > (Can the -X interpreter option be removed yet?) Doesn't Python convert class exceptions to strings when -X is used ? I would guess that many scripts already rely on the class based mechanism (much of my stuff does for sure), so by the time 1.6 is out, I think -X should be considered an option to run pre 1.5 code rather than using it for performance reasons. -- Marc-Andre Lemburg ______________________________________________________________________ Y2000: 50 days left Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4