我正在編寫一個程序,根據Google電子表格中的數據爲家人創建一個目錄條目。其中一項職能是列出家庭中的任何兒童以及他們的生日。然而,該程序在生日之前沒有明顯的原因打印撇號,例如, '01/01/01,我不明白爲什麼。我已將生日的數據轉換爲字符串,而其他字符串不會執行此操作。這是爲什麼發生?爲什麼Python在我的字符串中的數字之前顯示一個撇號?
這裏是源代碼的相關部分:
import gspread
gc =gspread.login('mylogin','password')
spreadsheet = gc.open_by_key("mykey")
worksheet = spreadsheet.get_worksheet(0)
Child1=(worksheet.cell(x,13)).value
Child1BD=(worksheet.cell(x,14)).value
Child2=(worksheet.cell(x,15)).value
Child2BD=(worksheet.cell(x,16)).value
Child3=(worksheet.cell(x,17)).value
Child3BD=(worksheet.cell(x,18)).value
Child4=(worksheet.cell(x,19)).value
Child4BD=(worksheet.cell(x,20)).value
# If there are no children, return without doing anything.
if Child1 == "n/a":
return;
# If there is one child only, print the child's name and birthday.
elif Child2 == "n/a" and Child1 != "n/a":
print str(Child1)+"- "+str(Child1BD)
return;
# If thre are exactly two children, print their names and birthdays.
elif Child3 == "n/a" and Child2 != "n/a":
print str(Child1)+"- "+str(Child1BD)
print str(Child2) +"- "+str(Child2BD)
return;
# If there are exactly three children, print their names and birthdays.
elif Child4 == "n/a" and Child3 != "n/a":
print str(Child1)+"- "+str(Child1BD)
print str(Child2) +"- "+str(Child2BD)
print str(Child3) +"- "+str(Child3BD)
return;
# If there are four children, print their names and birthdays.
elif Child4 != "n/a":
print str(Child1)+"- "+str(Child1BD)
print str(Child2) +"- "+str(Child2BD)
print str(Child3) +"- "+str(Child3BD)
print str(Child4) +"- "+str(Child4BD)
return;
'print repr(Child1)'打印出來了什麼? – Blender 2013-03-07 03:33:32