mercredi 29 juin 2016

python coercing to unicode when trying to compile with py2exe in os package


I'm trying to export to an exe file a script but when it's compiling it gives me "coercing to unicode" error.

Here's a screen capture: cmd

the setup.py file:

from distutils.core import setup
import py2exe

setup(console=['headers.py'],
options = {
              "py2exe":{
                  "packages": ["linecache", "csv", "Tkinter", "Tkinter", "tkFileDialog", "itertools", "os"]
                  }})

and the code:

import Tkinter, tkFileDialog, os, csv, itertools
root = Tkinter.Tk()
root.withdraw()
dirname = tkFileDialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')
for subdir, dirs, files in os.walk(dirname):
    for file in files:
        with open (os.path.join(subdir, file), 'rb') as csvfile:
            #Check if the file has headers#
            if 'Result  :  Query Result' in csvfile.readline():
                if not os.path.exists(subdir + '/output/'):
                    os.makedirs(subdir + '/output/')
                with open(os.path.join(subdir + '/output/', file), 'wb') as out:
                    reader = csv.reader(itertools.islice(csvfile, 6, None), delimiter=',')
                    writer = csv.writer(out)
                    for row in reader:
                        #replace NIL occurrences with empty strings
                        try:
                            row[:] = [ele if ele != "NIL" else "" for ele in row]
                        except IndexError:
                            pass
                        writer.writerow(row) 

It seems to be the os import that I'm doing but I don't know why. I've looked it up and there's nothing that seems to help me.


Aucun commentaire:

Enregistrer un commentaire