用小Python脚本创建exe

2024-09-30 14:27:05 发布

您现在位置:Python中文网/ 问答频道 /正文

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

使用py2exe我一直在尝试使用this tutorial创建可执行文件:

我可以创建名为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)))

Tags: csvinforifdeflineexeglobal