# 创建 file_create() 函数,作用:创建文件(尤其是.py文件)
# 该函数共有4个参数:
#namn -文件名
#extension -文件扩展名,即 后缀
#content -文件内容
#path -文件坐在的目录路径
#path_SetPath -设置 文件路径 的文件 的路径。
# def file_create(name,content,extension='py',path=None):
# full_path = path + name + '.' + extension
# file = open(full_path,'w')
# file.write(content)
# file.close()
# print('文件 ' + name + '.' + extension + ' 已被创建在 ' + path + ' 中。')
# file_create('test','# hello world') # 调用函数
def file_create(name,extension='py',content=None,path=None,path_SetPath='F:/TMP_j/path_NewFile.txt'):
# 判断 如果没有输入'文件名'就结束函数,并返回 0 :
if name is None:
return 0
# 判断 如果没有输入'路径'就结束函数,并返回 0 :
if path is None :
file_path = open(path_SetPath,'r')
path = file_path.readline()
print(path)
# full_path = path + name + '.' + extension
# file = open(full_path,'w')
# file.write(content)
# file.close()
# print('文件 ' + name + '.' + extension + ' 已被创建在 ' + path + ' 中。')
# return path + name + '.' + extension
file_create('test') # 调用函数
PY tmp代码
最新推荐文章于 2025-02-15 17:28:04 发布