在< module>中的文件“< string>"第1行, NameError:名称''未在ATOM中定义 [英] File "<string>", line 1, in <module> NameError: name ' ' is not defined in ATOM

查看:168
本文介绍了在< module>中的文件“< string>"第1行, NameError:名称''未在ATOM中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪,因为我的代码在在线python解释器中工作正常,但是当我在Atom的Linux Mint中运行它时,输入一个字时会出现以下错误消息:

It's weird because my code works fine in online python interpreter but when I run it in linux mint with Atom, I have this error message when I enter a word:

File "<string>", line 1, in <module>
NameError: name 'lol' is not defined

这是我的代码

# -*- coding: utf-8 -*-

word = str(input(" Enter a word : "))
reverse = word[::-1]
if reverse == word:
  print("it is a palindrome, félicitation : ")
else:
  print(" it is not a palindrome : ")

推荐答案

尝试使用raw_input而不是input.听起来好像在在线解释器中,您可能正在Python 3中运行代码,其中input的行为类似于Python 2的raw_input,并在本地使用Python 2.

Try using raw_input instead of input. It sounds like in the online interpreter you might be running the code in Python 3, in which input behaves like Python 2's raw_input, and using Python 2 locally.

在python 2中,input导致您的代码在寻找输入的定义,而不是将其视为字符串.

In python 2, input results in your code looking for a definition for your input, rather than taking it as a string.

这篇关于在&lt; module&gt;中的文件“&lt; string&gt;"第1行, NameError:名称''未在ATOM中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆