Unicode string handling problem (revised)

Discussion in 'Python' started by Richard Schulman, Sep 6, 2006.

  1. The appended program fragment works correctly with an ascii input
    file. But the file I actually want to process is Unicode (utf-16
    encoding). This file must be Unicode rather than ASCII or Latin-1
    because it contains mixed Chinese and English characters.

    When I run the program I get an attribute_count of zero. This
    is incorrect for the input file, which should give a value of fifteen
    or sixteen. In other words, the count function isn't recognizing the

    ",

    characters to be counted in the line read.

    Here's the program:

    in_file = open("c:\\pythonapps\\in-graf1.my","rU")
    try:
    # Skip the first line; make the second available for processing
    in_file.readline()
    in_line = in_file.readline()
    attribute_count = in_line.count('",')
    print attribute_count
    finally:
    in_file.close()

    Any suggestions?

    Richard Schulman
    (delete 'xx' characters for email reply)
     
    Richard Schulman, Sep 6, 2006
    #1
    1. Advertising

  2. Richard Schulman

    John Machin Guest

    Richard Schulman wrote:
    [snip]
    > in_line = in_file.readline()

    [snip]

    We'd already deduced that that line was incorrectly published.
    Please don't start new threads like this; if you want to make a
    correction, do a couple-of-lines reply to your original message.
    Now please leave this new thread alone, and reply to the
    much-more-meaningful questions in the original thread.
     
    John Machin, Sep 6, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Schemenauer
    Replies:
    2
    Views:
    300
    Dieter Maurer
    Aug 24, 2005
  2. Tina
    Replies:
    2
    Views:
    497
  3. Richard Schulman

    Unicode string handling problem

    Richard Schulman, Sep 6, 2006, in forum: Python
    Replies:
    8
    Views:
    352
    John Machin
    Sep 7, 2006
  4. pete

    3n+1 problem revised

    pete, May 12, 2006, in forum: C Programming
    Replies:
    3
    Views:
    328
    Keith Thompson
    May 15, 2006
  5. joy99
    Replies:
    4
    Views:
    412
    joy99
    Aug 16, 2009
Loading...

Share This Page