SourceForge logo
SourceForge logo
Menu

matplotlib-devel

From: John H. <jdh...@ac...> - 2005年07月29日 14:57:01
Anyone know of a simple fix for this
> python unicode_demo.py -dSVG
 File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_svg.py", line 196, in draw_text
 self._svgwriter.write (svg)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 136: ordinal not in range(128)
From: M. <ja...@fc...> - 2005年07月29日 19:13:30
John Hunter wrote:
> 
> Anyone know of a simple fix for this
> 
>> python unicode_demo.py -dSVG
> 
> File
> "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_svg.py",
> line 196, in draw_text
> self._svgwriter.write (svg)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
> position 136: ordinal not in range(128)
 I found this link very useful to understand this type of problems:
http://evanjones.ca/python-utf8.html
-- 
José Abílio
From: Fernando P. <Fer...@co...> - 2005年07月29日 20:07:27
John Hunter wrote:
> Anyone know of a simple fix for this
> 
> 
>>python unicode_demo.py -dSVG
> 
> 
> File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_svg.py", line 196, in draw_text
> self._svgwriter.write (svg)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 136: ordinal not in range(128)
I recently had to fix the same bug for ipython. Here's what my 
stumble-in-the-dark approach to unicode bug fixing (no net access at home that 
day) produced:
 def _str(self,glob,loc):
 """Evaluate to a string in the given globals/locals.
 The final output is built by calling str(), but if this fails, the
 result is encoded with the instance's codec and error handling policy,
 via a call to out.encode(self.codec,self.encoding_errors)"""
 result = []
 app = result.append
 for live, chunk in self.chunks:
 if live: app(str(eval(chunk,glob,loc)))
 else: app(chunk)
 out = ''.join(result)
 try:
 return str(out)
 except UnicodeError:
 return out.encode(self.codec,self.encoding_errors)
where the codec stuff is set via:
 Optional arguments:
 - codec('utf_8'): a string containing the name of a valid Python
 codec.
 - encoding_errors('backslashreplace'): a string with a valid error 
handling
 policy. See the codecs module documentation for details.
 These are used to encode the format string if a call to str() fails on
 the expanded result."""
 if not isinstance(format,basestring):
 raise TypeError, "needs string initializer"
 self.format = format
 self.codec = codec
 self.encoding_errors = encoding_errors
This is all in ipython's Itpl.py module, in case you want to look closer (the 
crash was there b/c that's the machinery used for prompt printing).
cheers,
f
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /