On Wed, 25 May 2005 21:15:42 +0800 (CST), yuan ye <[EMAIL PROTECTED]> wrote:
>Hello everyone, >If you have ever used UltraEdit, you will know that it >can convert encoding from Unix/Mac to Dos. Does >anybody know how I can do it in Python without the >help of UltraEdit? For example, to convert the >encoding from Unix/Mac to Dos for a TXT file. > I think this is not a proper use of the word "encoding". There is no such thing as a "DOS encoding" or a "Unix/Mac encoding". Instead, I rather suspect that this is translating the end-of-line characters, which ARE different between the three environments. Unix marks end-of-line with a single linefeed (0x0A). The Mac marks end-of-line with a single carriage return (0x0D). DOS uses both (0x0D, 0x0A). If you have Python 2.3 or greater, it allows you to open a file for "universal newlines", where it will detect the standard in use and handle it appropriately. So, for short files, you can do this: open('localEndings.txt','w').write( open('unknownEndings.txt','rU').read() ) -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32