Python comes with many built-in functions which are always available as part of the language. We’ve already seen some of them in the previous sections. This page gives an overview of the most important ones.

When called without any argument, dir() returns a list of names in the current local scope.

If you’re starting a new interactive session in Terminal, dir() will return only private attributes and methods (with names starting with double underscores) which are made available by the Python language:

getattr()

The getattr() function is used to get an attribute from a given object. Instead of accessing the attribute directly, we pass the object and the attribute name to the getattr() function, and get a value back. This ‘indirect’ approach allows us to write code that is more abstract and more reflexive.

Here’s a simple example using an open font in RoboFont. Let’s imagine that we want to print out some font info attributes. We could access them directly one by one, like this: