python怎么创建文件夹_如何使用python在文件夹中创建文本文件?
我試圖在一個不是運行腳本的目錄的文件夾中創建一個.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()
如果您對我的代碼有任何疑問,請隨時提問!在
總結
以上是生活随笔為你收集整理的python怎么创建文件夹_如何使用python在文件夹中创建文本文件?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 生成器推导式
- 下一篇: Vi 编辑器常用命令