class Net():
def __init__(self):
self.net_list = ['G_A','G_B','D_A','D_B']
self.netG_A = 'ga'
self.netG_B = 'gb'
self.netD_A = 'da'
self.netD_B = 'db'
def print_net(self):
for net_name in self.net_list:
net = getattr(self, 'net' + net_name)
print(net)
n = Net()
n.print_net()
结果:
ga
gb
da
db
标签:__,name,self,getattr,使用,print,net,方法
From: https://www.cnblogs.com/xyf9474/p/17124110.html