From: Peter Otten on 12 Jan 2010 11:03 Lie Ryan wrote: > On 01/12/10 23:50, Jens Müller wrote: >>> To convert unicode into str you have to *encode()* it. >>> >>> u"...".decode(...) will implicitly convert to ASCII first, i. e. is >>> equivalent to >>> >>> u"...".encode("ascii").decode(...) >>> >>> Hence the error message >> >> Ah - yes of course. >> >> And how can you use the system's default encoding with errors=ignore? >> The default encoding is the one that is used if no parameters are given >> to "encode". >> >> Thanks again! > > >>>> import sys >>>> sys.getdefaultencoding() > 'ascii' >>>> u'M\xfcnchen, pronounced > [\u02c8m\u028fn\xe7\u0259n]'.encode(sys.getdefaultencoding(), 'ignore') > 'Mnchen, pronounced [mnn]' > > > unless this is for debugging, I doubt ignoring error in this particular > case is an acceptable solution (how do you pronounce [mnn]?) Also, I think on most systems >>> sys.getdefaultencoding() 'ascii' You might try >>> locale.getpreferredencoding() 'UTF-8' instead. Peter
First
|
Prev
|
Pages: 1 2 Prev: problem with multiprocessing and defaultdict Next: Is python not good enough? |