我正在编写一个程序来根据来自谷歌电子表格的数据为一个家庭创建一个目录条目。其中一个功能是列出家庭中的所有孩子以及他们的生日。但是,该程序在生日之前无缘无故地打印一个撇号,例如'01/01/01,我不知道为什么。我已将生日的数据转换为字符串,而我的其他字符串没有这样做。为什么会这样?
以下是源代码的相关部分:
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;