简体   繁体   English

在python3上使用python调试器会引发NameError:未定义名称“ raw_input”

[英]Using python debugger on python3 throws NameError: name 'raw_input' is not defined

Has it changed? 它改变了吗? I am just using it as import pdb; pdb.set_trace() 我只是将其用作import pdb; pdb.set_trace() import pdb; pdb.set_trace() but in the line the pdb is used it throws now: import pdb; pdb.set_trace()但在使用pdb的行中,它现在抛出:

NameError: name 'raw_input' is not defined

For those asking for full traceback: 对于那些要求完整追溯的人:

My app traceback and then:
    if not serializer.is_valid():
  vi +48  /usr/lib/python3.5/bdb.py  # trace_dispatch
    return self.dispatch_line(frame)
  vi +66  /usr/lib/python3.5/bdb.py  # dispatch_line
    self.user_line(frame)
  vi +259 /usr/lib/python3.5/pdb.py  # user_line
    self.interaction(frame, None)
  vi +346 /usr/lib/python3.5/pdb.py  # interaction
    self._cmdloop()
  vi +319 /usr/lib/python3.5/pdb.py  # _cmdloop
    self.cmdloop()
  vi +32  /home/user/.virtualenvs/myapp/lib/python3.5/site-packages/noseprogressive/wrapping.py  # cmdloop
    orig_raw_input = raw_input
NameError: name 'raw_input' is not defined

Looks very python3.5 pdb to me, nothing about 2.7 pdb 在我看来非常python3.5 pdb,与2.7 pdb无关

Here's the issue. 这是问题。

You are using noseprogressive library with 1.5.1 version which is too old around 6 years ago ( 26 Mar 2013 which is developed for Python 2.7 I guess). 您正在使用1.5.1版本的noseprogressive库,该库在大约6年前就已经太旧了(我猜这是针对Python 2.7开发的2013年3月26日 )。

https://github.com/erikrose/nose-progressive/blob/1.5.1/noseprogressive/wrapping.py#L32 https://github.com/erikrose/nose-progressive/blob/1.5.1/noseprogressive/wrapping.py#L32

They didn't handle the exception where they are assigning raw_input to a variable orig_raw_input which is why you are getting the NameError when using raw_input 他们没有在将raw_input分配给变量orig_raw_input的情况下处理异常,这就是为什么使用raw_input时会出现NameError原因


But in the latest version 1.5.2 , they handled it properly using try and catch . 但是在最新版本1.5.2 ,他们使用try and catch正确地处理了它。

https://github.com/erikrose/nose-progressive/blob/1.5.2/noseprogressive/wrapping.py#L33 https://github.com/erikrose/nose-progressive/blob/1.5.2/noseprogressive/wrapping.py#L33

Try updating the noseprogressive library to the latest version which is 1.5.2 and it should be fine. 尝试将noseprogressive库更新为最新版本1.5.2 ,应该没问题。

Hope this helps. 希望这可以帮助。

For Python 3.x, use input() . 对于Python 3.x,请使用input()。 For Python 2.x, use raw_input() . 对于Python 2.x,请使用raw_input()。 Don't forget you can add a prompt string in your input() call to create one less print statement. 别忘了,您可以在input()调用中添加提示字符串,以减少一条打印语句。 input("GUESS THAT NUMBER!") here is the documentation https://docs.python.org/3/whatsnew/3.0.html input(“ GUESS THAT NUMBER!”)这是文档https://docs.python.org/3/whatsnew/3.0.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM