Sometimes, I find it hard to distinguish between a method and an attribute by it’s name without appending parentheses.
For example:
there’re keys() method and text attribute in xml.etree.ElementTree.Element class.
text:The text attribute can be used to hold additional data associated with the element.
keys():Returns the elements attribute names as a list.
Is there some basic rules/conventions to make text an attribute, but keys() a method?
If I make text() a method, and keys an attribute. It still seems OK.
The only real distinction is that one is callable and one is not, so you can use the builtin function
callable()with the actual object (not a string with the name of it) to determine whether or not it is callable.In your case: