Googleスプレッドシートのデータに基づいて、家族のディレクトリエントリを作成するプログラムを作成しています。機能の1つは、家族の子供を誕生日とともに一覧表示することです。ただし、プログラムは、明確な理由なしに、誕生日の前にアポストロフィを印刷しています。たとえば、'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;