【发布时间】:2016-06-15 01:33:32
【问题描述】:
这是我的完整代码。它提供了 rigt 输出,但它没有向函数 update2new 和 main 函数返回任何内容。在命令提示符下
嗨
从 [abc_20160301_(file1).csv] 获取数据.....
处理数据....
已删除 NIL..
成功执行[abc_20160301_(file1).csv]......
好的
但是成功执行的文件名应该像 "Successfully Executed[abc_20160301.csv]" 这是因为函数没有返回任何值。
import csv
import csv as csv
import os
import shutil
import xlrd
import re
from datetime import datetime, date, time, timedelta
import time
def update2new(src_dest):
print("Hi")
fileProcess(src_dest)
os.remove('outfile.csv')
os.remove('new.csv')
return src_dest
def fileProcess(src):
print('\nFetching Data From [ {} ] .....'.format(str(src)), end='\n')
#Removing first 6 rows
FIRST_ROW_NUM=1
ROWS_TO_DELETE = {1,2,3,4,5,6}
with open(src, 'rt') as infile, open('outfile.csv', 'wt') as outfile:
outfile.writelines(row for row_num, row in enumerate(infile, FIRST_ROW_NUM)
if row_num not in ROWS_TO_DELETE)
print('\nProcessing Data....',end='\n')
#Removing NIL from the file
with open("outfile.csv") as f, open ('new.csv','wt') as out:
data = f.read()
new_data = re.sub("NIL"," ",data)
data = new_data
out.write(data)
print("Deleted NIL..")
customDate = (date.today()-timedelta(1)).strftime('%Y%m%d')
#Removing Total from last row
with open("new.csv") as f_origin, open ('D:\Pritam\PRS\abc_'+customDate+'.csv','wt') as dest:
for line in f_origin:
if not line.startswith('Total'):
dest.write(line)
return dest
def main():
print("<------Initializing Updating Process------>")
srcFile ='abc_20160301_(file1).csv'
update2new(srcFile)
print('\nSuccessfully Executed [ {}]......'.format(str(srcFile)),end='\n')
print ("OK")
# ---------------------------------------------------------------------------------------------------
# This is THE standard boilerplate that calls THE main() function
if __name__ == '__main__':
main()
【问题讨论】:
-
update2new(srcFile)在您的main中。你似乎没有捕捉到return...
标签: python python-2.7 csv python-3.x return