最近我尝试访问__init__
方法属性,以更改其值并从另一个函数自动重新计算某些属性。你知道吗
我试过一些基本的方法,但没有成功地得到我想要的。这是问题代码:
class Square():
def __init__(self, length, width):
self.length = length
self.width = width
@property
def Area(self):
return self.length * self.width
A1 = Square(length=3, width=3) ## made an object
print(A1.Area) #9
def check():
a = []
b = [1,3,2]
t = [100,20,23]
d = [0.1]
c = 4
for i in d:
c += 6
d += [0.1]
if A1.Area < 8: ## eg. if A1.length=2 and A1.width=2 have been changed in the __init__ attribute this A1.Area would be 4 and the condtion is ture and the loop break ends
break ## here break the loop finally if the A1.Area is altered by the conditions
for k in range(len(b)):
a.append(c + b[k])
if c + b[k] > t[2]:
A1.length = 2## here i am trying to change the __init__ attribute
A1.width = 2 ## here i am trying to change the __init__ attribute
print(k)
c = c - 6
break
return c
我不知道您在check函数中真正想做什么,但以下几点对我来说很好:
相关问题 更多 >
编程相关推荐