<br><br><div class="gmail_quote">On Wed, Jan 21, 2009 at 1:59 PM, bilgin arslan <span dir="ltr"><<a href="mailto:a.bilgin.a@gmail.com">a.bilgin.a@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br>
I am trying to write a list of words to into a text file as two<br>
colons: word (tab) len(word)<br>
such as<br>
<br>
standart 8<br>
<br>
I have no trouble writing the words but I couldn't write integers. I<br>
always get strange characters, such as:<br>
<br>
GUN<br>
㐊娀䄀䴀䄀一ഀ5COCUK<br>
㐊䬀䄀䐀䤀一ഀ5EV<br>
...<br>
㜊夀䄀䴀䄀ഀ4YATSI<br>
㔊娀䤀䰀䜀䤀吀ഀ� </blockquote><div><br><br>Looks like an encoding problem to me.<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
(the integers also seem to be incorrect)<br>
I use the following form inside a loop to produce this<br>
current = unicode(word)+" "+str(len(word))<br>
ofile.write(current) <br></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
I know about struct and I tried to used it but somehow I always got a<br>
blank character instead of an int.<br>
<br>
import struct<br>
format = "i"<br>
data = struct.pack(format, 24)<br>
print data</blockquote><div><br><br>Struct encodes the data as a string. 24 encoded as a byte string is represented as 18 00 00 00 (these are hex). All of these values are unprintable, so you get a blank instead. You're original idea should work once you get the encoding problem fixed.<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
Any ideas?<br>
I use macosx and eclipse. The code also uses unicode encoding</blockquote><div><br>Unicode is NOT an encoding. It is a standard. You're probably thinking of the UTF-8 encoding, one of the 5 different "unicode" encodings. This page does a great job of explaining what Unicode actually is.<br>
<br><a href="http://www.joelonsoftware.com/articles/Unicode.html">http://www.joelonsoftware.com/articles/Unicode.html</a><br><br>Try using ofile.write(current.encode("UTF-8")) and see if that helps.</div></div><br>