Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 13
    It is perfectly okay to access the __dict__ attribute. Introspection is fundamental to the language. The attribute was made public for a reason :-) Commented Jun 1, 2013 at 23:56
  • 10
    But everything in Python is "public". There are no distinctions (except the leading underscore convention) between the implementation variables used in an instance, and the public interface it presents. Especially in a dictionary-like object: the line between instance methods, and dictionary values which are functions, is a bit blurry. Commented Jun 2, 2013 at 0:58
  • If you're passing the arguments as named parameters? do_something(**args.__dict__) Commented Oct 26, 2018 at 11:59
  • why doesn't the obvious way work e.g. dict(args)? Or at least why is this not the top answer/recommended? Commented Dec 14, 2021 at 18:27
  • A reason to grab the __dict__ would be for logging purposes as Object of type Namespace is not JSON serializable Commented Jan 8, 2024 at 18:14