<tfoot id='CBNgQ'></tfoot>

        <small id='CBNgQ'></small><noframes id='CBNgQ'>

      1. <legend id='CBNgQ'><style id='CBNgQ'><dir id='CBNgQ'><q id='CBNgQ'></q></dir></style></legend>
          <bdo id='CBNgQ'></bdo><ul id='CBNgQ'></ul>

        <i id='CBNgQ'><tr id='CBNgQ'><dt id='CBNgQ'><q id='CBNgQ'><span id='CBNgQ'><b id='CBNgQ'><form id='CBNgQ'><ins id='CBNgQ'></ins><ul id='CBNgQ'></ul><sub id='CBNgQ'></sub></form><legend id='CBNgQ'></legend><bdo id='CBNgQ'><pre id='CBNgQ'><center id='CBNgQ'></center></pre></bdo></b><th id='CBNgQ'></th></span></q></dt></tr></i><div id='CBNgQ'><tfoot id='CBNgQ'></tfoot><dl id='CBNgQ'><fieldset id='CBNgQ'></fieldset></dl></div>
      2. NameError:Python 3 中未定义全局名称“xrange"

        时间:2024-04-20
          <bdo id='6HsGA'></bdo><ul id='6HsGA'></ul>

          1. <legend id='6HsGA'><style id='6HsGA'><dir id='6HsGA'><q id='6HsGA'></q></dir></style></legend>
          2. <tfoot id='6HsGA'></tfoot>

                  <small id='6HsGA'></small><noframes id='6HsGA'>

                    <tbody id='6HsGA'></tbody>

                  <i id='6HsGA'><tr id='6HsGA'><dt id='6HsGA'><q id='6HsGA'><span id='6HsGA'><b id='6HsGA'><form id='6HsGA'><ins id='6HsGA'></ins><ul id='6HsGA'></ul><sub id='6HsGA'></sub></form><legend id='6HsGA'></legend><bdo id='6HsGA'><pre id='6HsGA'><center id='6HsGA'></center></pre></bdo></b><th id='6HsGA'></th></span></q></dt></tr></i><div id='6HsGA'><tfoot id='6HsGA'></tfoot><dl id='6HsGA'><fieldset id='6HsGA'></fieldset></dl></div>

                  本文介绍了NameError:Python 3 中未定义全局名称“xrange"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I am getting an error when running a python program:

                  Traceback (most recent call last):
                    File "C:Program Files (x86)Wing IDE 101 4.1srcdebug	server\_sandbox.py", line 110, in <module>
                    File "C:Program Files (x86)Wing IDE 101 4.1srcdebug	server\_sandbox.py", line 27, in __init__
                    File "C:Program Files (x86)Wing IDE 101 4.1srcdebug	serverclassinventory.py", line 17, in __init__
                  builtins.NameError: global name 'xrange' is not defined
                  

                  The game is from here.

                  What causes this error?

                  解决方案

                  You are trying to run a Python 2 codebase with Python 3. xrange() was renamed to range() in Python 3.

                  Run the game with Python 2 instead. Don't try to port it unless you know what you are doing, most likely there will be more problems beyond xrange() vs. range().

                  For the record, what you are seeing is not a syntax error but a runtime exception instead.


                  If you do know what your are doing and are actively making a Python 2 codebase compatible with Python 3, you can bridge the code by adding the global name to your module as an alias for range. (Take into account that you may have to update any existing range() use in the Python 2 codebase with list(range(...)) to ensure you still get a list object in Python 3):

                  try:
                      # Python 2
                      xrange
                  except NameError:
                      # Python 3, xrange is now named range
                      xrange = range
                  
                  # Python 2 code that uses xrange(...) unchanged, and any
                  # range(...) replaced with list(range(...))
                  

                  or replace all uses of xrange(...) with range(...) in the codebase and then use a different shim to make the Python 3 syntax compatible with Python 2:

                  try:
                      # Python 2 forward compatibility
                      range = xrange
                  except NameError:
                      pass
                  
                  # Python 2 code transformed from range(...) -> list(range(...)) and
                  # xrange(...) -> range(...).
                  

                  The latter is preferable for codebases that want to aim to be Python 3 compatible only in the long run, it is easier to then just use Python 3 syntax whenever possible.

                  这篇关于NameError:Python 3 中未定义全局名称“xrange"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:exec() 和变量范围 下一篇:builtins.TypeError:必须是 str,而不是 bytes

                  相关文章

                    <legend id='QRw1B'><style id='QRw1B'><dir id='QRw1B'><q id='QRw1B'></q></dir></style></legend><tfoot id='QRw1B'></tfoot>

                      • <bdo id='QRw1B'></bdo><ul id='QRw1B'></ul>

                      <small id='QRw1B'></small><noframes id='QRw1B'>

                      <i id='QRw1B'><tr id='QRw1B'><dt id='QRw1B'><q id='QRw1B'><span id='QRw1B'><b id='QRw1B'><form id='QRw1B'><ins id='QRw1B'></ins><ul id='QRw1B'></ul><sub id='QRw1B'></sub></form><legend id='QRw1B'></legend><bdo id='QRw1B'><pre id='QRw1B'><center id='QRw1B'></center></pre></bdo></b><th id='QRw1B'></th></span></q></dt></tr></i><div id='QRw1B'><tfoot id='QRw1B'></tfoot><dl id='QRw1B'><fieldset id='QRw1B'></fieldset></dl></div>