[Pythonmac-SIG] python characters on a mac?

Karsten Wolf karstenwo at googlemail.com
Wed Jun 29 11:40:17 CEST 2011


> I was directed to send the following query to this email address.


That's too bad. If you're not here on your own you might be reluctant  
to learn...

Try this. Assuming your text file was encoded in UTF-8. Read the docs  
about unicode and encoding.


Am 23.06.2011 um 20:35 schrieb Joseph Grcar:

> #!/usr/bin/python
> input=open("example.txt","r")
> output=open("out.txt","w")
> for line in input:
     # convert string to unicode. Given that your output contained  
2 ? for ã
     # my guess is UTF-8
     line = unicode(line, "UTF-8")
     for character in line:
        output.write ("%s\n" % character)


> Why does python does not make use of the character codes that are  
> used by the Mac OS?  Is there a way to tell python to recognize the  
> OS character set?


Because it can't. There is no way to know which encoding a file is in.

-karsten


More information about the Pythonmac-SIG mailing list