Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在处理文件,在处理它们之后,我需要按升序使用数字名称保存它们,例如 1.txt、2.txt 等。手动我会做如下:
Variable_1 = "C:\\1.txt" Variable_2 = "C:\\2.txt"
for i in range(10): filename = "C:\\%d.txt" % i with open(filename, 'a') as f: ....
就这么简单,但您也可以使用生成器来创建文件名(由您决定)