Unicode string handling problem (revised)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Schulman

    #1

    Unicode string handling problem (revised)

    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:\\pytho napps\\in-graf1.my","rU")
    try:
    # Skip the first line; make the second available for processing
    in_file.readlin e()
    in_line = in_file.readlin e()
    attribute_count = in_line.count(' ",')
    print attribute_count
    finally:
    in_file.close()

    Any suggestions?

    Richard Schulman
    (delete 'xx' characters for email reply)
  • John Machin

    #2
    Re: Unicode string handling problem (revised)


    Richard Schulman wrote:
    [snip]
    in_line = in_file.readlin e()
    [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.

    Comment

    Working...