I want to check if my global variable item got rewrite with the value of my function copy()
I do not know how does scope works
The problem here is that, when a class register() is called, and the instance is done with proof, the value is [0] again, which is not my goal. I want to re-write it with de value of de inner function
class register():
item = [0]
print(f'item before function -> {item} <id> = {id(item)}')
def __init__(self, quantity = '20', fabric_c = 'client', fabric_p = 'own'):
self.quantity = quantity
self.fabric_c = fabric_c
p_c = True
def copy(self):
if p_c == True:
line = self.quantity + ' meters ' + self.fabric_c
item = line
print(f'printing description during execution function -> {line} <id> = {id(item)})')
return item
print(f'item after function -> {item} <id> = {id(item)}')
proof = register()
proof.copy()
print(f'proof.item = {proof.item} outside of class -> {id(proof.item)}')
# [out] : item before function -> [0] <id> = 140627839165312
# [out] : printing description during execution function -> 20 meters client <id> = 140627839182128)
# [out] : proof.item = [0] outside of class -> 140627839165312
And also as you can see, the id value of item in the inner function ,is no the same as the value of the global variable item