×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    1

    Reading German text

    Hello,

    I'm trying to read simple text files in German using Python. I'm using the built-in file functions ('open', etc.). The problem is that characters with umlauts (for example, a with two dots over it) are not reading correctly. Can anyone tell me how to read text files in unicode? Thanks for your help.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    386

    Re: Reading German text

    It depends what encoding was used to save the file you're reading. If it's a plain text file it most probably is encoded with latin1 or utf8. To read this as unicode use the following code:

    Code:
    f = open(filename, 'r')
    text = f.read().decode('latin1')
    f.close()
    For utf8 substitute 'latin1' with 'utf8'. Keep in mind that these two are not the only ones.

Similar Threads

  1. Reading text file
    By cvz in forum Symbian
    Replies: 4
    Last Post: 2008-08-28, 10:52
  2. Problem while Reading text file in Nokia3650
    By lalithunt in forum Mobile Java General
    Replies: 5
    Last Post: 2008-07-30, 17:19
  3. Reading A Text File Woes
    By _nomad_ in forum Symbian
    Replies: 1
    Last Post: 2005-02-02, 10:09
  4. Replies: 0
    Last Post: 2004-11-24, 18:49
  5. Replies: 0
    Last Post: 2002-07-24, 16:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •