基于
Spyder version 5.0
change_set.csv
no,file_from,format_from,file_to,format_to,,ANSI = mbcs,UTF-8 = utf-8,UTF-8 with BOM = utf-8-sig
1,./utf-8/d14.csv,utf-8,./utf-8-sig/d14.csv,utf-8-sig,mbcs,,,
2,./utf-8/d15.csv,utf-8,./utf-8-sig/d15.csv,utf-8-sig,mbcs,,,
3,./utf-8/d16.csv,utf-8,./utf-8-sig/d16.csv,utf-8-sig,mbcs,,,
4,./utf-8/d17.csv,utf-8,./utf-8-sig/d17.csv,utf-8-sig,mbcs,,,
5,./utf-8/d18.csv,utf-8,./utf-8-sig/d18.csv,utf-8-sig,mbcs,,,
6,./utf-8/d19.csv,utf-8,./utf-8-sig/d19.csv,utf-8-sig,mbcs,,,
7,./utf-8/d20.csv,utf-8,./utf-8-sig/d20.csv,utf-8-sig,mbcs,,,
format_batch_change_v2.py
import re
import pandas as pd
def file_ex(file_from,format_from,file_to,format_to,col_n):
file = file_from
file_o = file_to
f = open(file, "r",encoding=format_from)
d = f.readlines()
# print(f.readlines())
f = open(file_o,'w+',encoding=format_to)
k = 0
n = 0
for line in d:
# line1 = line.strip('\n')
line1 = line.replace('\n',',')
line1 = line1.replace(' ',"")
indices_object = re.finditer(pattern=',', string=line1)
indices = [index.start() for index in indices_object]
k=k+1
if(k==1):
print(line1[0:indices[0]])
n = int(line1[0:indices[0]])
if(k==n and n!=0):
break
# print(len(line1))
# print(len(indices))
# print(indices[col_n])
line2=line1[0:indices[col_n]]
print(line2,file=f)
f.close()
d = pd.read_csv(file_o,sep=',',encoding=format_to,header=None)
return d
col_n = 15
fileName = 'change_set.csv' # class id cid and data file name in set.csv
mset = pd.read_csv(fileName,header=0) # get set info
for k in mset['no']:
# print(k)
file_from = mset['file_from'][k-1]
file_to = mset['file_to'][k-1]
format_from = mset['format_from'][k-1]
format_to = mset['format_to'][k-1]
print(file_to)
d = file_ex(file_from,format_from,file_to,format_to,col_n)
to exe
cmd
pyinstaller --onefile -i "logo.ico" .\format_batch_change_v2.py