0

I successfully created an .exe using py2exe with a simple test script I found on a tutorials website. The script I am using, however, does not seem to work. My code uses the csv module and dict reader with two .csv inputs.

I run the python setup.py p2exe command, and I get a flash of a command prompt, but that disappears before I can read anything on it. And once it disappears, I do not have the correct .csv file output that I would get if I just ran the script in python.

Can anyone offer any advice or things to try? Or is there a way I could get that pesky cmd window to stay open long enough for me to see what it says?

Thanks. My script is below.

import csv

def main():
iFileName = 'DonorsPlayTesting.csv'
oFileName = iFileName[:-4] + '-Output' + iFileName[-4:]
iFile = csv.DictReader(open(iFileName))
oFile = csv.writer(open(oFileName, 'w'), lineterminator = '\n')

iDirectory = csv.DictReader(open("DonorsDirectory.csv"))
oNames = {}
directory = {}
for line in iDirectory:
   directory[line['Number']] = line['Name']

for key in directory.keys():
    oNames[directory[key]] = 0

out_header = ['Name', 'Plays']
oFile.writerow(out_header)

for line in iFile:
    if line['Type'] == "Test Completion":
        if line['Number'] in directory:
            oNames[directory[line['Number']]] += 1
        elif line['Number'] not in directory:                
            oNames[line['Number']] = 'Need Name'


oFile.writerows(oNames.items())


main()
Paden
  • 1
  • I'm guess the error is related to not specifying the full path to the file, though you should provide any error messages or output you get so we can do better than guess – wnnmaw Feb 07 '14 at 20:57
  • 2
    To see the output, open a command prompt *first*, then run the exe from it. That way it won't disappear when it exits – mhlester Feb 07 '14 at 21:02
  • 2
    Or you could add `raw_input('Hit ENTER to close.')` after your `main()` to keep the window open. – felerian Feb 07 '14 at 21:03
  • 3
    except if it's erroring before getting that far (i.e. module doesn't exist to `import`), then it'll still close – mhlester Feb 07 '14 at 21:07
  • Well, the cmd window still closed, but I managed to print screen it with lightning fast reflexes. It said something about an issue with import linecach then import csv, it said no module named csv. However, when I move the required input .csv files into the "dist" folder py2exe uses, it ran correctly. What do I need to do to allow this file to run correctly, whenever it is the same directory as the 2 input .csvs? – Paden Feb 12 '14 at 06:07

0 Answers0