Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

8.2. Dynamic attribute access

Python attribute access uses straightforward syntax, shared with other imperative languages like Java and C#. Through properties, you can control what happens when individual attributes are fetched or set; but, with Python, you can provide access to arbitrary attributes through the __getattr__ method.

The flip side of this is being able to dynamically access attributes when you have their names stored as strings. Python supports this through a set of built-in functions.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial