我用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)))
我很惊讶它居然能在非编译版本中工作。我看不出
dowork()
在哪里被调用。在我认为您只需要在scip的底部添加
dowork()
相关问题 更多 >
编程相关推荐