Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'backslash': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:files': 0.09; 'subject:java': 0.09; 'whitespaces': 0.09; 'subject:python': 0.10; 'def': 0.13; '"""encode': 0.16; 'encode': 0.16; 'this:': 0.16; 'this?': 0.19; 'header:In-Reply-To:1': 0.22; 'string': 0.24; 'subject: .': 0.29; 'unicode': 0.29; 'header:User- Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'something': 0.35; 'subject:How': 0.35; '8bit%:86': 0.37; 'could': 0.37; 'received:org': 0.38; 'characters': 0.39; 'else': 0.39; 'to:addr:python.org': 0.40; 'achieve': 0.61; 'skip:\xd0 20': 0.77 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Serhiy Storchaka Subject: Re: How to generate java .properties files in python Date: Mon, 05 Dec 2011 22:05:43 +0200 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: 79.124.196.219 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111110 Thunderbird/8.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 14 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323115809 news.xs4all.nl 6920 [2001:888:2000:d::a6]:58220 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16683 03.12.11 23:34, Arnaud Delobelle написав(ла): > 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") You must also encode backslash ('\\'), whitespaces and control characters (ord(c)<=32), '=' and ':' (key/value delimiters), '#' (comment) and '!'. And don't forget characters with code >0xFFFF.