object - Python purpose of % attribute prefix -
i've seen python objects attributes %values
. can't access such attributes, raise syntaxerror
. seem require setattr
created without syntaxerror
:
class a(object): pass = a() setattr(a, "%values", 42) a.%values # results in syntaxerror: invalid syntax class b(object): def __init__(self): self.%values = 42 # results in syntaxerror: invalid syntax
does %
have purpose or meaning here? why can %values
set using setattr
, otherwise raises syntaxerror
?
does % have purpose or meaning here?
most precisely prevent accessing attributes using regular dot notation, because, have seen, can't. discourages using them, making them in way "private" whatever application using them. there better ways achieve this, though. call smell if saw code this.
why can %values set using setattr, otherwise raises syntaxerror?
attributes stored in dictionary, , dictionary keys can anything. don't have follow same rules python identifiers; python verify strings. (some older versions of python enforce names passed setattr
valid python identifiers, removed language time ago.)
Comments
Post a Comment