return super().get_keyword_names()
时间: 2023-09-12 19:12:55 浏览: 37
这是一个 Python 中的方法调用语句,用于调用当前类的父类(超类)中的 `get_keyword_names()` 方法,并返回其返回值。
在这个语句中,`super()` 函数返回当前类的父类对象,然后调用该对象中的 `get_keyword_names()` 方法。这个方法可能是父类中已经实现好的方法,也可能是子类中重写的方法。无论是哪种情况,都可以通过这个语句来调用对应的方法,并返回其返回值。
相关问题
import math class QE: __a = 0 __b = 0 __c = 0 def __init__(self,a,b,c): QE.__a = a QE.__b = b QE.__c = c def geta(self): return QE.__a def getb(self): return QE.__b def getc(self): return QE.__c def getD(self): return QE.__b^2-4*QE.__a*QE.__c def getRoot1(self): M = QE.getD() if M < 0: print("该方程无根!") elif M == 0: print("x1 = x2 = {:.2f}".format( (-QE.__b - math.sqrt(QE.__b ^ 2 - 4 * QE.__a * QE.__c)) / 2 * QE.__a )) else: print("x1 = {:.2f}".format( (-QE.__b - math.sqrt(QE.__b ^ 2 - 4 * QE.__a * QE.__c)) / 2 * QE.__a )) QE.getRoot2() def getRoot2(slef): print("x2 = {:.2f}".format((-QE.__b + math.sqrt(QE.__b ^ 2 - 4 * QE.__a * QE.__c)) / 2 * QE.__a)) a = int(input("请输入a值")) b = int(input("请输入b值")) c = int(input("请输入c值")) B = QE(a,b,c) B.getRoot1()
出现这个错误是因为你在调用 `QE.getD()` 方法时,没有将实例对象作为参数传递给该方法。因为 `getD()` 方法是实例方法,需要使用 `self` 来引用实例对象的属性。你可以将 `QE.getD()` 改为 `self.getD()`,这样就能正确地引用实例对象了。此外,你在 `getRoot2()` 方法中拼写错误,应该是 `self` 而不是 `slef`。下面是修改后的代码:
import math
class QE:
__a = 0
__b = 0
__c = 0
def __init__(self,a,b,c):
QE.__a = a
QE.__b = b
QE.__c = c
def geta(self):
return QE.__a
def getb(self):
return QE.__b
def getc(self):
return QE.__c
def getD(self):
return QE.__b**2-4*QE.__a*QE.__c
def getRoot1(self):
M = self.getD()
if M < 0:
print("该方程无根!")
elif M == 0:
print("x1 = x2 = {:.2f}".format((-QE.__b - math.sqrt(QE.__b**2 - 4 * QE.__a * QE.__c)) / 2 * QE.__a))
else:
print("x1 = {:.2f}".format((-QE.__b - math.sqrt(QE.__b**2 - 4 * QE.__a * QE.__c)) / 2 * QE.__a))
self.getRoot2()
def getRoot2(self):
print("x2 = {:.2f}".format((-QE.__b + math.sqrt(QE.__b**2 - 4 * QE.__a * QE.__c)) / 2 * QE.__a))
a = int(input("请输入a值"))
b = int(input("请输入b值"))
c = int(input("请输入c值"))
B = QE(a,b,c)
B.getRoot1()
ef get_keyword_names(self): for item in dir(self): kw = getattr(self, item) if hasattr(kw, "internal_robot_var_info"): for var in kw.internal_robot_var_info: if var in self.internal_robot_var_spec: assert self.internal_robot_var_spec[var] == kw.robot_name, \ RuntimeError( f"变量名{var} 由两个不同的关键字创建:" f"{self.internal_robot_var_spec[var]}、" f"{kw.robot_name}" ) self.internal_robot_var_spec[var] = kw.robot_name return super().get_keyword_names() 解释一下这段代码的作用
这段代码的作用是获取一个类(或其子类)中的所有可用关键字,并将其返回。关键字是指类中的方法,可以通过 Robot Framework 测试框架来调用。
具体地说,这段代码通过 `dir(self)` 获取类中的所有属性和方法,然后遍历这些属性和方法。如果一个方法有 `internal_robot_var_info` 属性,那么它会被认为是一个关键字,并将其中定义的变量名(即 `internal_robot_var_info` 中的元素)添加到 `internal_robot_var_spec` 字典中,同时将这个方法的名称作为变量名所属的关键字名称。
在添加变量名之前,代码会检查这个变量名是否已经被另一个关键字使用。如果是,则会抛出一个运行时异常。如果不是,则会将这个变量名和当前关键字的名称添加到 `internal_robot_var_spec` 字典中。
最后,这个方法调用了 `super().get_keyword_names()`,并将其返回值作为自己的返回值。这个方法是在 Robot Framework 的库类中定义的,用于获取库中所有可用的关键字名称。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)