|
发表于 2022-10-18 10:39:30
|
显示全部楼层
本楼为最佳答案
以下是示例代码:
- import sys
- from pathlib import Path
- if len(sys.argv) < 2:
- print('没有输入足够的关卡文件,程序即将退出')
- input('按任意键退出程序')
- sys.exit()
- for file in sys.argv[1:]: # 使用循环依次读取关卡文件
- lvl_file = Path(file)
- new_file = Path(f'{lvl_file.stem}(困难模式){lvl_file.suffix}') # 使用关卡文件名生成新文件名
- # 由于不知道具体的关卡内容,下面的代码只是做示范
- # 打开关卡文件,读取其中内容
- with lvl_file.open() as f: # 此处没有指明打开文件的模式和编码,可能会出问题
- data = f.read()
- # 新建并打开困难模式的文件,然后写入数据
- with new_file.open('w', encoding='utf-8') as f:
- f.write(data)
- print('处理完毕,按任意键退出')
- input()
复制代码 |
|