0
def store_inFile(Name,Address,Area,Postcode):
    #open the file
    File2 = open("Fines.txt","rt")

    #write the name address and post code to file and save to file
    File2.write(str(Name)+"\n"+str(Address)+"\n   "+str(Area)+"\n      "+str(Postcode));File2.close()

    #set File to open the datatbase
    File =open("DATABASE.txt","rt")
    NumP_Input = str(input("Number plate of person speeding. ").upper())

    #loop each line intil the numberplate gets a match
    for line in File:
        Numberplate,Name,Address,Area,Postcode = line.split("|") #here use whatever you have splitting your database ie , . / ( |
        if NumP_Input.upper() == Numberplate:
            #output name address and number plate
            print("Fine sent to \n \n"+str(Name)+"\n"+str(Address)+"\n   "+str(Area)+"\n      "+str(Postcode));store_inFile(Name,Address,Area,Postcode)

データベースから読み取りたいのですが、ユーザーがデータベースに関連付けられたナンバー プレートを入力すると、すべての情報 (パラメーター) が別のファイルに送信されます。

4

1 に答える 1

1

入力を確認してください - ファイル「DATABASE.txt」。line「|」がないものがあります そのため、コードが要求するように「正確に 5 つの部分に分割」されません。

Numberplate,Name,Address,Area,Postcode = line.split("|")

例:

>>> line = "hello, world"
>>> Numberplate,Name,Address,Area,Postcode = line.split("|")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack
于 2015-05-31T19:22:11.430 に答える