0
class myclass(object):
def __init__(self, arg1, arg2, arg3):
self.arg1 = arg1
self.arg2 = arg2
self.arg3 = arg3
def printattribute(self, arg):
print(self.arg)
a = myclass(1,2,3)
a.printattribute(arg2)
,並把它打印的a.arg2
的價值,但我不斷收到a do not have arg attribute
。如何使Python理解和點號後更改arg
,讓這樣的事情
def createlist(self, flag):
myset = set()
if flag == 'size':
for myfile in self.group:
myset.add(myfile.size)
if flag == 'head':
for myfile in self.group:
myset.add(myfile.head)
if flag == 'tail':
for myfile in self.group:
myset.add(myfile.tail)
if flag == 'hash':
for myfile in self.group:
myset.add(myfile.hash)
return sorted(myset)
變成
def createlist(self, flag):
myset = set()
for myfile in self.group:
myset.add(myfile.flag)
return sorted(myset)