The basic answer is "you can't do so reliably". See this question.
You can get an approximation with [attr for attr in dir(obj) if attr[:2] + attr[-2:] != '____' and not callable(getattr(obj,attr))]
.
However, you shouldn't rely on this, because:
Because dir()
is supplied primarily as a convenience for use at an interactive prompt, it tries to supply an interesting set of names more than it tries to supply a rigorously or consistently defined set of names, and its detailed behavior may change across releases.
In other words, there is no canonical way to get a list of "all of an object's attributes" (or "all of an object's methods").
If you're doing some kind of dynamic programming that requires you to iterate over unknwon fields of an object, the only reliable way to do it is to implement your own way of keeping track of those fields. For instance, you could use an attribute naming convention, or a special "fields" object, or, most simply, a dictionary.
inspect
but can't get it 100% right, but that module might help? – Monometallicvars
function or the field.__dict__
for your object? – Thisbe