我试图在一个不是运行脚本的目录的文件夹中创建一个.txt文件。我有一个脚本所在的文件夹,我可以在脚本所在的同一个目录中创建该文件夹,但它不会在该文件夹中创建文本文件。我通常遇到两个错误中的一个:PermissionError: [Errno 13] Permission denied或,FileNotFoundError: [Errno 2] No such file or directory:
这是一个密码管理员顺便说一句,为了防止五个人告诉我它不安全,我知道这一点,这个项目是纯粹的教育,我总是使用占位符。在
也有类似的问题,但它们都是针对java或c++。。。在
这是我的代码:def main():
import os
import os.path
abc = open("userpassfile.txt", "r+")
userpassfile = abc.read().strip().split()
actCheck = input('Do you already have an account?')
if (actCheck == 'Yes' or actCheck == 'yes'):
loginUser = input('What is your username?')
loginPass = input('What is yout password?')
if (loginUser and loginPass in userpassfile):
dirCheck = input('Account Settings? [y/n]')
if (dirCheck == 'y' or dirCheck == 'Y'):
print('This function is not working yet!')
addpassCheck = input('Would you like to add a password?')
if (addpassCheck == 'yes' or addpassCheck == 'Yes'):
abc123 = open(loginUser + '.txt', "r+")
huehuehue = abc123.read().strip().split()
addpass1 = input('What service is the pass')
addPass2 = input('What is the password')
abc123.write('(' + addpass1 + ',' + addPass2 + ')' + '\n')
else:
print('hihi')
else:
print("hehe")
else:
print('Incorrect password or username!')
else:
createAct = input('would you like to create one?')
if (createAct == 'Yes' or createAct == 'yes'):
save_path = 'C:/Users/Ari Madian/Desktop/Scripts/Python Scripts/Python Password Project'
createUser = input('What would you like your username to be?:')
createPass = input('What would you like your password to be?:')
abc.write(createUser + '\n')
abc.write(createPass + '\n')
os.makedirs(createUser)
completeName = os.path.join(save_path, createUser + ".txt")
main()
如果您对我的代码有任何疑问,请随时提问!在