namedtuples anamoly
Vinodhini Balusamy
me.vinob at gmail.com
Thu Oct 18 02:13:30 EDT 2018
Hi,
I tried using namedtuples and just found a behaviour which I am not able to
conclude as correct behaviour.
from collections import namedtuple
(n, categories) = (int(input()), input().split())
Grade = namedtuple('Grade', categories)
Grade.ID = 1
#print(Grade.ID)
ob = Grade(10, 50)
print(ob.ID)
print(ob.MARKS)
ob1 = Grade(20, 100)
print(ob1.ID)
2
ID MARKS
1
50
1
100
If we set GRADE.ID =1 , it has impact on all variables. Is this behaviour
just like class variable and it has global scope.
I expected ob.ID and ob1.ID to be 10.
Correct me if Iam wrong.
Appreciate any quick response.
Kind Rgds,
Vinu
More information about the Python-list
mailing list