python - 使用 Python 和 SQL 时出现 NamError
问题描述
我正在运行一个学生数据库并在 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()
和 create Table stement 看起来像这样
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")
推荐阅读
- google-sheets - 谷歌表格:有没有办法为一个增长到重复给定次数的序列制作一个数组
- uicollectionviewcell - 按住它们后如何让集合视图单元格摇晃?
- android - 通过 ADB 在 Android 中执行一组命令
- javascript - 如何发出 NodeJS 请求并将其通过管道传输到另一个响应中
- python - jinja2.exceptions.TemplateNotFound: index.html 渲染错误
- html - 无法更改文字大小
- reactjs - 单击同一链接后,React Router 无法重新呈现默认页面
- angular - Nrwl NX Monorepo(v12.3.5)上的 nx 服务应用程序(Angular v12.0.0)上的警告
- java - java.lang.SecurityException:com.myapp.android 与注册签名不匹配。FE:05:..01
- datatables - 使用固定表查找和乘法