使用小Python脚本创建exe

使用小Python脚本创建exe,python,Python,我使用Python2.7创建了一个小脚本 使用py2exe,我一直在尝试使用以下方法创建可执行文件: 我能够创建名为sdf.exe的exe文件 我在sdf.exe目录中有所有必要的库 从命令行运行sdf.exe时,我没有收到任何错误和消息;但是,该程序并没有完成它要做的事情,即创建一个名为output.csv的文件 当我运行sdf.py时,它可以正常工作;但是,运行sdf.exe不会执行任何操作,也不会返回任何错误。 我错过了什么?非常感谢你 以下是完整的代码: import csv the

我使用Python2.7创建了一个小脚本

使用py2exe,我一直在尝试使用以下方法创建可执行文件:

我能够创建名为
sdf.exe的exe文件

我在sdf.exe目录中有所有必要的库

从命令行运行sdf.exe时,我没有收到任何错误和消息;但是,该程序并没有完成它要做的事情,即创建一个名为
output.csv
的文件

当我运行
sdf.py
时,它可以正常工作;但是,运行
sdf.exe
不会执行任何操作,也不会返回任何错误。

我错过了什么?非常感谢你

以下是完整的代码:

import csv


thefile = []
output = []


def dowork():
    global thefile
    sourceFile='e.csv'
    thefile=ReadFile(sourceFile)
    CleanFile(sourceFile)    
    ProcessFile()
    AddHeader()
    WriteFile()

def ReadFile(filename):
    return list(csv.reader(open(filename, 'rb'), delimiter=',', quotechar='"'))[1:]

def CleanFile(sourceFile):
    global thefile
    iBalance=8
    iAging=7
    thefiletmp=[]
    for i, line in enumerate(thefile):
        if line[2]=='':
            del thefile[i]
        else:
            if thefile[i][iAging]=='':
                thefile[i][iAging]='0'
            thefiletmp.append(line[4:])
    thefile=thefiletmp


def ProcessFile():
    global thefile
    iCompany=1
    iNum=0
    iDate=2
    iAging=3
    iBalance=4
    COMPANIES=GetDistinctValues(1)
    mytemparray=[]
    mytempfile=[]
    TotalEachCustomer=0
    for company in COMPANIES:
        for line in thefile:
            if line[iCompany]==company:
                mytemparray.append(line[iCompany])
                mytemparray.append(line[iNum])
                mytemparray.append(line[iDate])
                iAgingCell=int(line[iAging])
                line[iBalance]=line[iBalance].replace(',','')
                if iAgingCell in range(0,31):
                    mytemparray.append(line[iBalance])
                    mytemparray.append('0')
                    mytemparray.append('0')
                    mytemparray.append('0')
                if iAgingCell  in range(31,61):
                    mytemparray.append('0')
                    mytemparray.append(line[iBalance])
                    mytemparray.append('0')
                    mytemparray.append('0')
                if iAgingCell  in range(61,91):
                    mytemparray.append('0')
                    mytemparray.append('0')
                    mytemparray.append(line[iBalance])
                    mytemparray.append('0')
                if iAgingCell >90:
                    mytemparray.append('0')
                    mytemparray.append('0')
                    mytemparray.append('0')
                    mytemparray.append(line[iBalance])
                TotalEachCustomer+=float(line[iBalance])
                mytemparray.append(line[iBalance])
                mytempfile.append(mytemparray)
                mytemparray=[]
        mytempfile.append(['','','','','','','',''])
        mytempfile.append([company+ " Total",'','','','','','',TotalEachCustomer])
        mytempfile.append(['','','','','','','',''])
        TotalEachCustomer=0
    thefile=mytempfile

def AddHeader():
    global thefile
    thefile[:0]=[['Account Name', 'Num','Date', '0-30', '31-60', '61-90', '91 Plus','Total']]

def WriteFile():
    global thefile
    out_file = open("output.csv", "wb")
    writer = csv.writer(out_file)
    for line in thefile:
        writer.writerow(line)
    out_file.close()


def GetDistinctValues(theColumn):
    return sorted(list(set(line[theColumn] for line in thefile)))

我很惊讶它能在非编译版本中工作。我看不到调用
dowork()
的位置


我想您只需要添加
dowork()
到scipt的底部

当您从命令行运行
sdf.exe
时,是否有任何错误输出?@monkey否我没有收到任何错误将文件放入哪个目录?@IgnacioVazquez Abrams,因为您可以看到脚本指示将output.csv文件创建到与程序相同的目录中,但它根本不是在创造它,我不知道它是否在创造它给另一个迪耶。我知道了。当前目录是什么?@АСёааааааааааааааааааааааааааааааа107。要将注释中的单词或短语斜体化,只需在其周围加下划线字符,如
\u斜体化
。通过单击“注释”文本框旁边的“帮助”链接,您可以找到有关该选项和其他格式化选项的信息。