2017-05-19 15 views
0

入力は第2の関数で使用できる最初の関数で収集されますが、すべてをテキストファイルに追加できる必要があります。それはあまりにも多くの議論を言う、助けてください!txtファイルに追加する引数が多すぎます

def newMember(): # gathers info to pass into sub routine to write to file 
    global surname, year, status, nights, points 
    print("Please enter the following information") 
    surname=input("Surname\n") 
    year=input("Year joined \n") 
    status=input("Membership status \n") 
    nights=input("Nights booked \n") 
    points=input("Points balance \n") 
    print("Please confirm these details \nSurname: "+surname+ "\nYear joined: "+year+ "\nMembership status: "+status+"\nNights booked: "+nights+ "\nPoints balance: "+points) 
    reply=input("Please type either Yes or No\n") 
    if reply in["Y","y","Yes","yes"]: #using an array in the selection to cover possible inputs 
     print("Thank you, these will now be written to file. Returning you to the main menu options") # write to file 
     time.sleep(3) 
     appendMember() 
    elif reply in ["n","N","no","No"]: 
     print("Sorry, you will now be prompted to enter the details again") 
     newMember() 
    else: 
     print("I'm sorry, I didn't quite catch that, the program will now restart") 
     newMember() 



def appendMember(): 
    global surname, year, status, nights, points 
    with open('SampleData2017.txt', mode="a")as crawdale: 
     crawdale.write[surname, year, status, nights, points] 
+0

なぜコードとして貼り付けられないのか分かりません。それは問題である最後の行ですが、姓のようなデータが1つ以上追加されません。 –

答えて

0

ファイルを書き込むには、1つのパラメータを渡す必要があります。このようなリストをカンマ区切りの文字列に変換できます。

def appendMember(): 
    global surname, year, status, nights, points 
    with open('SampleData2017.txt', mode="a") as crawdale: 
     crawdale.write(",".join([surname, year, status, nights, points])) 
+0

ああ私のおしっこ、私は午前9時からそれに取り組んできました、ありがとうございます! –

+0

@A.Teacher喜んでそれはあなたのために働く。 –

+0

@ A.Teacherお手伝いをして、スタックオーバーフローを歓迎します。この回答または他の誰かがあなたの問題を解決した場合は、それを承認済みとしてマークしてください –

関連する問題