# -*-coding:utf-8-*-
import sys
import csv
import os
import argparse
reload(sys)
sys.setdefaultencoding("utf-8")
def main():
parser = argparse.ArgumentParser(description="Change the txt file to csv.")
parser.add_argument("-i", action="store", dest="infile")
parser.add_argument("-o", action="store", dest="outfile")
parser_argument = parser.parse_args()
all_argument = [parser_argument.infile, parser_argument.outfile]
fatherdir = os.getcwd() # 代码所在目录
# 输入txt文件
if parser_argument.infile:
infilepaths = os.path.split(parser_argument.infile)
# 'C:\User\lenovo\Desktop\pakistan.txt' ---> ['C:\User\lenovo\Desktop','pakistan.txt']
if infilepaths[0]: # 完整路径
inputfile = parser_argument.infile
fatherdir = infilepaths[0]
# 'pakistan.txt' ---> ['','pakistan.txt']
else: # 只给一
python将txt转换为csv
最新推荐文章于 2024-07-03 11:33:55 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)