• <tfoot id='So7j5'></tfoot>

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

    1. <i id='So7j5'><tr id='So7j5'><dt id='So7j5'><q id='So7j5'><span id='So7j5'><b id='So7j5'><form id='So7j5'><ins id='So7j5'></ins><ul id='So7j5'></ul><sub id='So7j5'></sub></form><legend id='So7j5'></legend><bdo id='So7j5'><pre id='So7j5'><center id='So7j5'></center></pre></bdo></b><th id='So7j5'></th></span></q></dt></tr></i><div id='So7j5'><tfoot id='So7j5'></tfoot><dl id='So7j5'><fieldset id='So7j5'></fieldset></dl></div>
      • <bdo id='So7j5'></bdo><ul id='So7j5'></ul>
      <legend id='So7j5'><style id='So7j5'><dir id='So7j5'><q id='So7j5'></q></dir></style></legend>

        TypeError:缺少 1 个必需的位置参数:'self'

        TypeError: Missing 1 required positional argument: #39;self#39;(TypeError:缺少 1 个必需的位置参数:self)

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

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

              <legend id='JXVyD'><style id='JXVyD'><dir id='JXVyD'><q id='JXVyD'></q></dir></style></legend>
              • <tfoot id='JXVyD'></tfoot>
                  本文介绍了TypeError:缺少 1 个必需的位置参数:'self'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我无法克服错误:

                  Traceback (most recent call last):
                    File "C:UsersDomDesktop	est	est.py", line 7, in <module>
                      p = Pump.getPumps()
                  TypeError: getPumps() missing 1 required positional argument: 'self'
                  

                  我检查了几个教程,但似乎与我的代码没有什么不同.我唯一能想到的是 Python 3.3 需要不同的语法.

                  I examined several tutorials but there doesn't seem to be anything different from my code. The only thing I can think of is that Python 3.3 requires different syntax.

                  class Pump:
                  
                      def __init__(self):
                          print("init") # never prints
                  
                      def getPumps(self):
                          # Open database connection
                          # some stuff here that never gets executed because of error
                          pass  # dummy code
                  
                  p = Pump.getPumps()
                  
                  print(p)
                  

                  如果我理解正确,self 会自动传递给构造函数和方法.我在这里做错了什么?

                  If I understand correctly, self is passed to the constructor and methods automatically. What am I doing wrong here?

                  推荐答案

                  这里需要实例化一个类实例.

                  You need to instantiate a class instance here.

                  使用

                  p = Pump()
                  p.getPumps()
                  

                  小例子——

                  >>> class TestClass:
                          def __init__(self):
                              print("in init")
                          def testFunc(self):
                              print("in Test Func")
                  
                  
                  >>> testInstance = TestClass()
                  in init
                  >>> testInstance.testFunc()
                  in Test Func
                  

                  这篇关于TypeError:缺少 1 个必需的位置参数:'self'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                  • <legend id='VN6DL'><style id='VN6DL'><dir id='VN6DL'><q id='VN6DL'></q></dir></style></legend>

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

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