これがこれを投稿するのに間違った領域である場合は申し訳ありません。私がPython(一般的なコード)に触れてからしばらく経ちましたので、私が提示したコードは恐らく恐ろしいものですが、変数line1とline2をUSERDATA.pyファイルに書き込まず、理由がわかりません。感謝。乾杯
#import
import os
#
runstartText = 'Start success'
print(runstartText)
#setting values
file1 = './data'
file2 = './data/userpass'
file3 = './data/userpass/access.py'
newUserTEXT1 = 'Please input a valid email, username and password'
#checking/creating directorys
if not os.path.exists(file1):
os.makedirs(file1)
print('Created', file1)
if not os.path.exists(file2):
os.makedirs(file2)
print('Created', file2)
#def
def newUser():
print(newUserTEXT1)
username = input('Enter New System Username: ')
password = input('Enter New System Password: ')
passwordConfirm = input('Re-Enter New System Password: ')
if password == passwordConfirm:
print('Username and Password Stored')
line1 = 'username = ', username
line2 = 'username = ', password
apples = 1
if apples == 1:
userdatafile = open('USERDATA.py', 'w+')
userdatafile.writelines([line1, line2,])
userdatafile.close()
#-> store data
#-> to login
if password != passwordConfirm:
print('ERROR: Passwords do not match, please retry')
#-> restart newUser string
def login():
from USERDATA import username, password
print('Please Enter Username and Password:')
usernameTEMP = input('Username: ')
if usernameTEMP == username:
passwordTEMP = input('Password: ')
if passwordTEMP == password:
print('Successful Login!')
# -> to login
コードでは、実際にを呼び出すことはありませんnewUser()
。呼び出しを追加してエラーが発生しました:
line 37, in newUser userdatafile.writelines([line1, line2,]) TypeError: write() argument must be str, not tuple
したがって、内部のタプルをuserdatafile.writelines([line1, line2,])
文字列に置き換える必要がありますuserdatafile.writelines("".join(line1).join(line2))
そして、すべてが期待どおりに機能するはずです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加