如何在静态方法中获取类的名称,我有继承并想要派生类的名称
在下面的示例中,my_name()方法中的XXX应该有什么替代方法
class snake()
@staticmethod
def my_name():
print XXX.__name___
class python (snake)
pass
class cobra (snake)
pass
python.my_name()
# I want output to be python
cobra.my_name()
# I want output to be cobra
我已经意识到了@staticmethod -下一个问题,您应该使用类名从类中引用这些方法吗?
class C:
@staticmethod
def imstatic():
print("i'm static")
@staticmethod
def anotherstatic():
# Is this the proper python way?
C.imstatic()
@staticmethod
def brokenstatic():
# This do
我有一个C++类和一个static成员,意思是一个类成员。我希望使用自定义LLDB类型摘要显示该类成员的值,以方便使用Xcode进行调试。参加一个非常简单的课程演示:
class A
{
public:
int memberValue;
static int classValue;
};
int A::classValue;
int main()
{
A a;
a.memberValue = 8;
a.classValue = 42;
return 0;
}
在return语句上放置一个断点,运行该示例,在LLDB命令窗口中得到以下结果:
(l
我有这样的代码,
public class ComplexSO {
public static double real;
public static double imaginary;
public ComplexSO(double cReal, double cImaginary) {
real = cReal;
imaginary = cImaginary;
}
public static ComplexSO selfSquare() {
return new ComplexSO(Math.pow(
Python类属性和Java静态属性之间有什么区别?
例如,
在Python中
class Example:
attribute = 3
在Java中
public class Example {
private static int attribute;
}
在Python中,可以使用对实例的引用来访问静态属性?
在python中,如果我们定义一个名为Start的类,并用一个参数初始化它,如下所示…… class Start:
def __init__(self, a):
self.a = a 一旦定义好了,在将Start导入到另一个python文件中之后,有没有办法在类中创建一个函数或属性,这样我就可以直接构造这个类了? # Start.make or Start.make()
# Sample usage below
s = Start.make #initializes Start with the argument of 1 我尝试做的是让Start.make完成与Start
下面的java代码将打印带有A、和B值的两个列表。
import java.util.ArrayList;
public class MyClass {
private String value;
private ArrayList<String> ss = new ArrayList<>();
public MyClass(String value) {
this.value = value;
}
public void initialize(){
this.arrayList.add(t