这两者如何结合?(操作系统python)



我制作了这两包代码,但我不知道如何将密码放在带有操作系统库的文件夹中。如果有人能帮我就太好了

import random
small = "abcdefghijklmnopqrstuvwxyz"
capital = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
numbers = "123456789"
symbol = "[] { } () : ; @ $ &"
password = small + capital + numbers + symbol
lenght = 15
password = "".join(random.sample(password , lenght))
print(password)
import os
path = "C:\Users\Asus\Desktop\Chris\Python"
os.chdir(path)
files = "new file"
for i in range (1,11):
files = "new file" + str(i)
os.makedirs(files)

您可以使用open()函数创建一个新文件,如下所示:
f = open('filename.txt', 'w')

然后使用write()方法在文件中写入所需内容:
f.write('mycontent')

最后,不要忘记使用close()方法关闭文件:
f.close()

这也可以通过以下语法实现:

with open('filename.txt', 'w') as f:
f.write('mycontent') # you don't need to use f.close()

最新更新