我有这个代码来计算两个坐标之间的距离.这两个函数都在同一个类中.
但是如何在函数distToPoint中调用函数isNear?
class Coordinates:
def distToPoint(self, p):
"""
Use pythagoras to find distance
(a^2 = b^2 + c^2)
"""
...
def isNear(self, p):
distToPoint(self, p)
...
Run Code Online (Sandbox Code Playgroud) 我在使用以下 Python 代码时遇到问题:
class Methods:
def method1(n):
#method1 code
def method2(N):
#some method2 code
for number in method1(1):
#more method2 code
def main():
m = Methods
for number in m.method2(4):
#conditional code goes here
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,我得到
NameError: name 'method1' 未定义。
如何解决此错误?