<bdo id='eQJdE'></bdo><ul id='eQJdE'></ul>

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

    <tfoot id='eQJdE'></tfoot>

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

        时间:2023-09-10
        <i id='5AYRj'><tr id='5AYRj'><dt id='5AYRj'><q id='5AYRj'><span id='5AYRj'><b id='5AYRj'><form id='5AYRj'><ins id='5AYRj'></ins><ul id='5AYRj'></ul><sub id='5AYRj'></sub></form><legend id='5AYRj'></legend><bdo id='5AYRj'><pre id='5AYRj'><center id='5AYRj'></center></pre></bdo></b><th id='5AYRj'></th></span></q></dt></tr></i><div id='5AYRj'><tfoot id='5AYRj'></tfoot><dl id='5AYRj'><fieldset id='5AYRj'></fieldset></dl></div>
            • <bdo id='5AYRj'></bdo><ul id='5AYRj'></ul>
            • <legend id='5AYRj'><style id='5AYRj'><dir id='5AYRj'><q id='5AYRj'></q></dir></style></legend>
                <tbody id='5AYRj'></tbody>

            • <small id='5AYRj'></small><noframes id='5AYRj'>

                  <tfoot id='5AYRj'></tfoot>
                  本文介绍了Python:NameError:未定义全局名称“foobar"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我写了以下课程:

                  class myClass(object):
                      def __init__(self):
                          pass
                  
                      def foo(self, arg1, arg2):
                          pp = foobar(self, arg1, arg2)
                          if pp:
                              return 42
                          else
                              return -666
                  
                  
                      def foobar(self, arg1, arg2):
                          if arg1 == arg2:
                              return 42
                          else:
                              return None
                  

                  逻辑是荒谬的 - 忽略它.我试图这样做是从另一个实例方法调用一个实例方法 - 我得到一个 NameError.我最初认为这是由于 foo() 在定义之前调用了 foobar() - 但是在脚本中切换函数定义的顺序没有任何区别.

                  The logic is nonsensical - ignore it. What I am trying to so is to call an instance method from another instance method - and I am getting a NameError. I originally thought that this was due to foo() calling foobar() before it had been defined - but switching the order of the function definitions in the script made no difference.

                  有没有人知道是什么导致了这个错误,以及如何解决它?

                  Does anyone what's causing this error, and how to fix it?

                  推荐答案

                  Python 不会自动将代码范围限定为本地类;你需要告诉它.

                  Python doesn't scope code to the local class automatically; you need to tell it to.

                  pp = self.foobar(arg1, arg2)
                  

                  http://docs.python.org/tutorial/classes.html

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

                  上一篇:使用 lxml 从 python 中的 xml 中删除命名空间和前缀 下一篇:Django:“项目"与“应用程序"相比

                  相关文章

                  最新文章

                1. <tfoot id='om4pp'></tfoot>
                2. <small id='om4pp'></small><noframes id='om4pp'>

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

                      <legend id='om4pp'><style id='om4pp'><dir id='om4pp'><q id='om4pp'></q></dir></style></legend>

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