Python

Moderators: None (Apply to moderate this forum)
Number of threads: 400
Number of posts: 1055

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Python Tkinter and UTF-8 Posted by ami87 on 9 Aug 2010 at 8:35 AM
Hi.

I have a problem. I am meking a program which amkes .txt documents. The problem is a have to insert words, which have charecters like this: č,š,ž. You can find them in UTF-8 cade, but Idel givs me back this message:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "G:\pomozni3.py", line 305, in koncaj_delo
f.writelines(vnos)
TypeError: writelines() argument must be a sequence of strings

or:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "G:\pomozni3.py", line 242, in potrditev
f.write(ime1)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0160' in position 0: ordinal not in range(128)


The function in which this apper looks like this:
def koncaj_delo(self):
ime="%s"%self.listbox_partnerji.get(self.indeks_partner)
ime1=''
for i in range(len(ime)-1):
ime1=ime1+ime[i]
ime_datoteke=ime1+' '+self.now.strftime("%m.%Y")+'.txt'
f=open(ime_datoteke, 'a+')
naslov=f.readline()
f.close()
vnos="%s %s %s %s %s\n"%(self.datum_opravila.get(), self.cas_opravila.get(), self.time3, self.listbox_opravilo.get(self.indeks_opravilo), self.listbox_uporabnik.get(self.indeks_uporabik))
if naslov!=ime:
f=open(ime_datoteke, 'a+')
f.writelines(ime)
f.writelines(vnos)
f.close()
else:
f=open(ime_datoteke, 'a+')
f.writelines(vnos)
f.close()

Thenks for help.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.