使用 Python 和 SQL 时出现 NamError
Getting a NamError when using Python and SQL
我是 运行 学生数据库,在 pycharm 上使用 python 2.7。这是脚本
FirstName = input("Enter the Student's first name")
if not FirstName or type(FirstName) != str:
print("Enter a real name silly")
exit()
创建 Table 语句看起来像这样
drop table if exists StudentID;
drop table if exists FirstName;
drop table if exists LastName;
drop table if exists GPA;
drop table if exists Major;
drop table if exists FacultyAdvisor;
CREATE TABLE Student(
StudentID int PRIMARY KEY AUTOINCREMENT ,
FirstName varchar(25),
LastName varchar(25),
GPA NUMERIC,
Major varchar(10),
FacultyAdvisor varchar(25)
)
我得到的错误是
FirstName = input("Enter the Student's first name")
File "<string>", line 1, in <module>
NameError: name 'john' is not defined
我猜你正在使用 Python2
接收用户输入的字符串需要使用raw_input()
方法:
FirstName = raw_input("Enter the Student's first name")
我是 运行 学生数据库,在 pycharm 上使用 python 2.7。这是脚本
FirstName = input("Enter the Student's first name")
if not FirstName or type(FirstName) != str:
print("Enter a real name silly")
exit()
创建 Table 语句看起来像这样
drop table if exists StudentID;
drop table if exists FirstName;
drop table if exists LastName;
drop table if exists GPA;
drop table if exists Major;
drop table if exists FacultyAdvisor;
CREATE TABLE Student(
StudentID int PRIMARY KEY AUTOINCREMENT ,
FirstName varchar(25),
LastName varchar(25),
GPA NUMERIC,
Major varchar(10),
FacultyAdvisor varchar(25)
)
我得到的错误是
FirstName = input("Enter the Student's first name")
File "<string>", line 1, in <module>
NameError: name 'john' is not defined
我猜你正在使用 Python2
接收用户输入的字符串需要使用raw_input()
方法:
FirstName = raw_input("Enter the Student's first name")