我使用Python 2.7創建了一個小腳本。使用Python 2.7創建一個小腳本
使用py2exe我一直在試圖創建一個使用this tutorial的可執行文件:
我能夠創建一個名爲sdf.exe
我與sdf.exe目錄中的所有必要的庫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)))
你得到任何錯誤輸出的底部,當你在命令行運行'sdf.exe'? – ninMonkey
@monkey nope我沒有得到任何錯誤 –
它將文件放入哪個目錄? –