我有两个类,我想将“ Page”类用作“ Records”类的一部分,作为get set属性,我想在c#中做,但是在python中是初学者,所以不知道如何实现这一点。 ,我正在分享我所做的事情
在下面的C#中,我写了:
public class Records
{
public int num { get; set; }
public Page paging { get; set; }//how to write this line in python
}
public class Page
{
public int pagenumber { get; set; }
}
以上我想在python中实现的
class Records:
num=10
#paging=""
# def __init__(self):
# self.__num = num
def get_x(self):
return self.num
def set_x(self, num):
self.num = num
# def get_x(self):
# return self.paging
# def set_x(self, paging):
# self.paging = paging
class Page:
pagenumber=3
# def __init__(self,pagenumber):
# self.__pagenumber = 1
def get_x(self):
return self.pagenumber
def set_x(self, pagenumber):
self.pagenumber = pagenumber
objRecords = Records()
print("RECORDS",objRecords.num)
objPage = Page()
print("PAGE NUMBER",objPage.pagenumber)
答案 0 :(得分:0)
嗨,我通过以下解决方案解决了上述问题
class Records:
#num=10
def get_x(self):
return self.num
def set_x(self, num):
self.num = num
class Page:
#pagenumber=3
def get_x(self):
return self.pagenumber
def set_x(self, pagenumber):
self.pagenumber = pagenumber
if __name__ == "__main__":
obj = Records()
obj.pg=Page()
obj.pg.set_x(8)
result=obj.pg.get_x()
print(result)
#output:8