Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to generate java .properties files in python

Reply
Thread Tools

How to generate java .properties files in python

 
 
Arnaud Delobelle
Guest
Posts: n/a
 
      12-03-2011
Hi all,

I need to generate some java .properties files in Python (2.6 / 2.7).
It's a simple format to store key/value pairs e.g.

blue=bleu
green=vert
red=rouge

The key/value are unicode strings. The annoying thing is that the
file is encoded in ISO 8859-1, with all non Latin1 characters escaped
in the form \uHHHH (same as how unicode characters are escaped in
Python).

I thought I could use the "unicode_escape" codec. But it doesn't work
because it escapes Latin1 characters with escape sequences of the form
\xHH, which is not valid in a java .properties file.

Is there a simple way to achieve this? I could do something like this:

def encode(u):
"""encode a unicode string in .properties format"""
return u"".join(u"\\u%04x" % ord(c) if ord(c) > 0xFF else c for c
in u).encode("latin_1")

but it would be quite inefficient as I have many to generate.

--
Arnaud
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Failed to generate a user instance of SQL Server. Only an integratedconnection can generate a user instance. Harlan Messinger ASP .Net 2 03-28-2010 06:51 PM
Does anybody know a freeware-app which can generate UML diagrams from java files? Markus Java 7 08-19-2007 08:23 AM
How to generate warnings when How generate a warning when int is converted to bool or vice versa? PengYu.UT@gmail.com C++ 3 04-06-2006 11:24 PM
How to generate variable labels for same component within a generate loop Weng Tianxiang VHDL 5 02-16-2006 01:45 PM



Advertisments