我正在处理这个问题的roster.py部分,我得到了错误:
File "roster.py", line 17
print(f"{row["first"]} {row["middle"]} {row["last"]}, born {row["birth"]}")
^
SyntaxError: invalid syntax我的代码:
import sys
from cs50 import SQL
if len(sys.argv) != 2:
print("Needs two command-line argument")
exit(1)
db = SQL("sqlite:///students.db")
house = sys.argv[1]
results = db.execute("SELECT * FROM students WHERE house = ?", house)
for row in results:
if row["middle"] != None:
print(f"{row["first"]} {row["middle"]} {row["last"]}, born {row["birth"]}")
else:
print(f"{row["first"]} {row["last"]}, born {row["birth"]}")发布于 2020-08-20 10:26:00
你的引文是错误的。试试这个:
for row in results:
if row["middle"] != None:
print(f'{row["first"]} {row["middle"]} {row["last"]}, born {row["birth"]}')
else:
print(f'{row["first"]} {row["last"]}, born {row["birth"]}')发布于 2020-08-20 10:08:59
如果你正在尝试打印行的“中间”值等等,使用这个。
for row in results:
if row["middle"] != None:
print(f"{"+row["first"]+"} {"+row["middle"]+"} {"+row["last"]+"}, born {"+row["birth"]+"}")
else:
print(f"{"+row["first"]+"} {"+row["last"]+"}, born {"+row["birth"]+"}")https://stackoverflow.com/questions/63497295
复制相似问题