if groupName.group == "None":
error:
AttributeError: 'NoneType' object has no attribute 'group'
How to check if object has an attribute?
You want getattr()
, which you can pass a default value, or hasattr()
.
The error message is telling you that groupName
itself is None
.
In which case, there's little point in testing whether it has a particular attribute.
So you probably want something more like:
If groupName is not None:
print groupName.group
Or, if groupName
objects may not have a group
attribute:
If groupName is not None:
print getattr(groupName, 'group', None)
(Note: the last argument of getattr
is a default value that can be anything you want).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With