Trouble writing txt

Discussion in 'Python' started by bilgin arslan, Jan 21, 2009.

  1. Hello,
    I am trying to write a list of words to into a text file as two
    colons: word (tab) len(word)
    such as

    standart 8

    I have no trouble writing the words but I couldn't write integers. I
    always get strange characters, such as:

    GUN
    ãŠå¨€ä„€ä´€ä„€ä¸€à´€à¨€5COCUK
    ãŠä¬€ä„€ä€ä¤€ä¸€à´€à¨€5EV
    ....
    㜊夀䄀䴀䄀ഀ਀4YATSI
    㔊娀䤀䰀䜀䤀å€à´€à¨€ï¿½

    (the integers also seem to be incorrect)
    I use the following form inside a loop to produce this
    current = unicode(word)+" "+str(len(word))
    ofile.write(current)

    I know about struct and I tried to used it but somehow I always got a
    blank character instead of an int.

    import struct
    format = "i"
    data = struct.pack(format, 24)
    print data

    Any ideas?
    I use macosx and eclipse. The code also uses unicode encoding
     
    bilgin arslan, Jan 21, 2009
    #1
    1. Advertising

  2. bilgin arslan

    Jeff McNeil Guest

    On Jan 21, 1:59 pm, bilgin arslan <> wrote:
    > Hello,
    > I am trying to write a list of words to into a text file as two
    > colons: word (tab) len(word)
    > such as
    >
    > standart 8
    >
    > I have no trouble writing the words but I couldn't write integers. I
    > always get strange characters, such as:
    >
    > GUN
    > ãŠå¨€ä„€ä´€ä„€ä¸€à´€à¨€5COCUK
    > ãŠä¬€ä„€ä€ä¤€ä¸€à´€à¨€5EV
    > ...
    > 㜊夀䄀䴀䄀ഀ਀4YATSI
    > 㔊娀䤀䰀䜀䤀å€à´€à¨€
    >
    > (the integers also seem to be incorrect)
    > I use the following form inside a loop to produce this
    > current = unicode(word)+" "+str(len(word))
    > ofile.write(current)
    >
    > I know about struct and I tried to used it but somehow I always got a
    > blank character instead of an int.
    >
    > import struct
    > format = "i"
    > data = struct.pack(format, 24)
    > print data
    >
    > Any ideas?
    > I use macosx and eclipse. The code also uses unicode encoding


    I don't have a Mac in front of me, but I'll take a stab at it. You
    shouldn't need to bother with the struct module if you're simply
    trying to print out an integer's string value. What are you using to
    open 'ofile?' Can you post all of the relevant code?
     
    Jeff McNeil, Jan 21, 2009
    #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. John Carnahan

    File Access error - writing to .txt file

    John Carnahan, Jul 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    817
    John Carnahan
    Jul 18, 2003
  2. Uri
    Replies:
    4
    Views:
    316
    Fuzzyman
    May 11, 2004
  3. Sameen
    Replies:
    2
    Views:
    475
    Victor Bazarov
    Aug 29, 2005
  4. Jochen Brenzlinger
    Replies:
    7
    Views:
    5,850
    Roedy Green
    Sep 15, 2011
  5. Replies:
    3
    Views:
    91
    Jason Friedman
    Apr 2, 2014
Loading...

Share This Page