Py学习  »  Python

作用域在python中是如何工作的?

manish • 5 年前 • 1555 次点击  

我对面向对象的世界很陌生,我尝试用python编写代码并从另一个类调用一个类的函数。

霉菌

class A:

def funcA():
    return "sometext"

def funcB(self):
    self.funcA()  # calls func A internally from funcB 

第二代码.py

from Mycode import A

class B:
      def funcC(self):
          A.funcB(self)  # it gives error for call funcA() as it is unknown to class B
if __name__ == '__main__':

b=B()
b.funcC()

attributeerror:“b”对象没有“funca”属性在python中的类的作用域是如何工作的?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/40096
 
1555 次点击  
文章 [ 1 ]  |  最新文章 5 年前