A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/086675.html below:

Jython: How to import escaped Unicode and export utf-8?

Jython: How to import escaped Unicode and export utf-8?Martin von Loewis loewis at informatik.hu-berlin.de
Mon Apr 30 10:16:46 EDT 2001
Maurice Bauhahn <bauhahnm at clara.net> writes:

> Could you, Martin, or anyone else on the list, give a short Jython script
> which imports escaped unicode from a file (presumeably using codecs) and
> exports utf-8 to a file? My attempts at the same have not been successful.

Not sure what you mean by "importing" here. The file that you want to
read - is it Python source code (which you would load using the import
statement), or is a plain data file.

If it is a plain data file, why do you insist on storing it in
unicode-escaped encoding? I recommend to store it in UTF-8

>>> x=u"A test:\u1780, done."
>>> import codecs
>>> out=codecs.open("foo.txt","w","utf-8")
>>> out.write(x)
>>> out.close()
>>> infile=codecs.open("foo.txt","r","utf-8") 
>>> infile.read()
u'A test:\u1780, done.'
>>> ^D

So it works fine for me.

OTOH, you seem to have lists that you want to store; I recommend using
pickle for that.

Regards,
Martin

More information about the Python-list mailing list

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