Hello everybody

This is all my test code :

#!/usr/bin/env python
#-*- coding:Utf-8 -*-



from Tkinter import *
import Tkinter as tk
import tkFileDialog
import os
import ttk
import tkMessageBox
import psycopg2
from PIL import Image, ImageTk
import Image 
import ImageTk 
import os.path


chaine1 = "Bureau"
chaine2 = "Téléchargement"

listtest = []

listtest.append(chaine1)
listtest.append(chaine2)

chaine2.decode('UTF-8','strict')
chaine1.decode('UTF-8','strict')
print listtest[1]

print chaine2

print listtest

When i execute it , the result is :

Téléchargement
Téléchargement

I change decode to encode and the result is :

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)

I tried to put

chaine2.encode('utf-8')
chaine1.encode('utf-8')

and it never print :

Téléchargement
Téléchargement

as I wish

thank you very much for helping me ... :)

Try

>>> print "[%s]" % ", ".join(listtest)
[Bureau, Téléchargement]

Helloo friend , , thank you very much for your solution , well , my main problem is not with printing a list , but with pyinstaller .
I have a python code called Tmp2.py ( graphical interface from it I choose folders ) , and this Tmp2.py print in a label the path choosen ; the code of the function that choose the folder is :

def GetTarget0():   
    global rep0
    rep0 = tkFileDialog.askdirectory(initialdir="/",title='Choisissez un repertoire').encode('utf-8')
    if len(rep0) > 0:       
       print "vous avez choisi le repertoire source %s" % rep0
       listerep.append(rep0)
    else :
       print " ta tappe annule "

and the code of printing in the label is :

lab12 = Label(source1, text=" + %s"%rep0 , bg = "blue", fg = "black" )
       lab12.place( x=25 , y=80)

so if i'm running Tmp2.py directly it works great and print the path in the label , but after generating an executable "Tmp2" using pyinstaller , if I execute the application by double clicking on Tmp2 and after choosing a folder that it name contain "é" it blocks and don't pass to the next step of execution , and i can not know what is happening while running , because it is not executed from the Terminale , thank you for any ideas :)

Perhaps you should print intermediary information to a file to see what happens.

Hello Gribouillis , thank you for answering , but can you give me an example for what you said , thank you very much .

Hello Gribouillis , thank you for answering , but can you give me an example for what you said , thank you very much .

Well, for example

import logging
logging.basicConfig(
    format="%(filename)s [%(lineno)d] %(message)s", filename="tmp2log.log")
log = logging.getLogger("tmp2")
# ...
log.info("vous avez choisi le repertoire source %s" % rep0)
#...

Hello Gribouillis , thank you very much for your very good exemple , I've just tried again my apllication and it worked nice , I did change pyinstaller from the version python3.1 to python2.6 , but i am not sure realy from where the probleme was , thank you very much again Gribouillis , in this next step : i just need to know if it is possible to be able to enter to all under elements inside the zip file generated when double clicking on it ( by double clicking ) , because actualy ; if an under file or folder contain in it name "é" when i enter by double clicking i found it name change to "T??l??chargement" for exemple and couldn't enter to its under elements , thank you very much again :) .

Hello Gribouillis , thank you very much for your very good exemple , I've just tried again my apllication and it worked nice , I did change pyinstaller from the version python3.1 to python2.6 , but i am not sure realy from where the probleme was , thank you very much again Gribouillis , in this next step : i just need to know if it is possible to be able to enter to all under elements inside the zip file generated when double clicking on it ( by double clicking ) , because actualy ; if an under file or folder contain in it name "é" when i enter by double clicking i found it name change to "T??l??chargement" for exemple and couldn't enter to its under elements , thank you very much again :) .

It's difficult to answer since I don't know where and how you get Téléchargement replaced with T??l??chargement. There is most likely a simple solution using encoding. Does it happen only in the pyinstaller version or already with the pure python version ? Can you post your code ?

Hello , it happens however i execute the code ( from the executable "Tmp2" or by typping in terminal :

./Tmp2.py

, this is maybe the function that make the zip ok , this is the code of backup script :

#!/usr/bin/python
#-*- coding:Utf-8 -*-
import os
import time
import sys

source = []

print sys.argv

for i in range(len(sys.argv)):
          source.append(sys.argv[i])

source.remove(source[0])
source.remove(source[0])

print source
print sys.argv[1]

target_dir = sys.argv[1]

today = target_dir + os.sep + time.strftime('%Y%m%d')

now = time.strftime('%H%M%S')

if not os.path.exists(today):
    os.mkdir(today) 
     
print 'Sauvegarde reussie vers', today

target = today + os.sep + now + '.zip'
  
zip_command = "zip -qr {0} {1}".format(target, ' '.join(source)) # here the code make the zip receiving argument "source" , source is a list of paths of folders 
                                                                 # when i print source then i get "T??l??chargement inside .
                                       
if os.system(zip_command) == 0:
    print 'Sauvegarde reussie vers', target
    
else:
    print 'Echec de la sauvegarde'

Thank you very much for your answers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.