1、基本文件格式
import sys def start(): print(__file__) if __name__ == "__main__": argvList = sys.argv start()
2、文件操作
import os #文件操作引用
#创建或覆盖文件 with open(os.path.dirname(__file__)+'\1.txt',"w") as fw: fw.write(f.read())
#读取文件 with open(os.path.dirname(__file__)+'\files\1.txt') as f: print(f.read())
#获取文件夹列表,并循环输出 for path in os.listdir(os.path.dirname(__file__)+'\files'): print(path);
# -*- coding:utf-8 -*- import sys import os def start(): #读取配置文件 print(__file__) print(os.listdir(os.path.dirname(__file__)+'\files')); with open(os.path.dirname(__file__)+'\1.txt',"w") as fw: for path in os.listdir(os.path.dirname(__file__)+'\files'): with open(os.path.dirname(__file__)+'\files\'+ path) as f: fw.write(f.read()) fw.write(' ') #os.system('pause') if __name__ == "__main__": argvList = sys.argv start()