下面是程序一部分的代碼。這部分打印用戶輸入的行(與idnum相同)。它從所有6個文件中檢索數據都很好,但是當它打印出來時,有一行將每一條數據分隔開來。我需要做什麼才能使程序在沒有行距的情況下打印數據。從文件中檢索數據
1 smith
1 john
1 02/01/1234
1 4 pigeon street
1 123456765432234432
1 male
idnum= int(input("Enter id number: "))
def display():
line = open("Surname", "r").readlines()[idnum-1]
print (line)
line = open("Forename", "r").readlines()[idnum-1]
print (line)
line = open("Date of birth", "r").readlines()[idnum-1]
print (line)
line = open("Home address", "r").readlines()[idnum-1]
print (line)
line = open("Home phone number", "r").readlines()[idnum-1]
print (line)
line = open("Gender", "r").readlines()[idnum-1]
print (line)
import os.path
if os.path.exists("Surname"):
display()
else:
print("No data exists.")
你也可以使用'打印(line.rst rip('\ n'))' – coder