python - python 3名称错误
问题描述
编辑:感谢您提供有用的答案!我下载了 Python 3.7.0,但你是对的,我的 Mac 运行的是 Python 2.7。我现在有作业:) 弄清楚如何让它运行 3.7。如果我有更多问题,我会回来的。谢谢!
初学者在这里。使用 Python Launcher 在 Mac 中执行时出现 NameError。在 Python 3.7.0 Shell 中进行测试时,它可以正常工作。我已经阅读了 NameError 问题的其他答案,但不明白我做错了什么。帮助表示赞赏。
使用的代码
first_name = input ("Hi, what's your first name? ")
print ("Hi," , first_name)
收到错误
Traceback (most recent call last):
File "/Users/imperio/Documents/pythonpractice/Name.py", line 1, in <module>
first_name = input ("Hi, what's your first name? ")
File "<string>", line 1, in <module>
NameError: name 'Imperio' is not defined
解决方案
这很可能是因为您没有使用 Python 3+ 执行它。
请检查输出python -V
以查看您正在使用哪个版本执行代码。
在 Mac 上,您可能已经安装了这两个版本,Python 3 有时别名为python3 file.py
这是您的程序转换为有效的 Python2:
first_name = raw_input ("Hi, what's your first name? ")
print ("Hi, {}".format(first_name))
推荐阅读
- javascript - 统计一个月内子文档mongodb交易中的产品数量
- java - 具有复合主键的 JPA @OneToMany
- php - 为什么空('0')=真;空('00')=假;
- javascript - setState 和 Axios POST 请求不起作用
- amazon-web-services - 谷歌云 API 网关覆盖请求参数
- node.js - 将消息存储在数据库中并使用 socket.io 发出它们的最佳方法是什么?
- java - 如何在 gridbaglayout 中使 jtextarea 可滚动
- mongodb - 如何重置 MongoDB 连接?
- css - Shopify 液体模板中带有文本叠加的图像
- docker - Zeppelin 中的 python.sql 错误:NameError: name 'pd' is not defined