python2x NameError: name ‘abc‘ is not defined
生活随笔
收集整理的這篇文章主要介紹了
python2x NameError: name ‘abc‘ is not defined
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本問題在python 3x 中不會出現 ,
下面說下問題發生的原因
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")content = input("input message:")
print content
輸入 數字問題 ,當輸入字母或者文字的時候出現下面的問題
這個問題的處理方法有2中
1 輸入字母或者文字的時候帶上雙引號 “” 或者單引號
感覺這個處理不是很好
所以建議使用方法2
把input 換成 raw_input
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding("utf-8")content = raw_input("input message:")
print content
python 3x 不支持 raw_input 不過python3 x 中不會出現,上面的問題
當然還有一種可能,就是你使用的python 2x 中使用input 而你輸入的是字母或者問題,這一種情況,你需要把input 改為raw_input 或者 在你的工具把python 的版本修改 3x
總結
以上是生活随笔為你收集整理的python2x NameError: name ‘abc‘ is not defined的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信个性签名乐观
- 下一篇: 扁头怎样扎头发才好看?