I’m using the User object from the Google App Engine environment, and just tried the following:
pprint(user)
print vars(user)
The results:
pprint(user)
users.User(email='test@example.com',_user_id='18580000000000')
print vars(user)
{'_User__federated_identity': None, '_User__auth_domain': 'gmail.com',
'_User__email': 'test@example.com', '_User__user_id': '1858000000000',
'_User__federated_provider': None}
Several issues here (sorry for the multipart):
- How come I’m not seeing all the variables in my object. It’s not showing
auth_domain, which has a value? - Is there a way to have it list properties that are = None? None is a legitimate value, why does it treat those properties like they don’t exist?
- Is there a way to get pprint to line-break between properties?
pprintis printing thereprof the instance, whilevarssimply returns the instance’s__dict__, whose repr is then printed. Here’s an example:You see that the special method
__repr__here (called bypprint(), theprintstatement,repr(), and others) explicitly only includes theamember, while the instance’s__dict__contains bothaandb, and is reflected by the dictionary returned byvars().