Coming from a .NET background and having applied SOLID principles to software development, I was surprised by the lack of inversion of control containers for Python.
The few discussions I read online implied that Python doesn’t need an IoC framework because it is a dynamically typed language. Dynamically typed languages eliminate the need to use interfaces, they do not do away with the need for inversion of control.
IoC is used to decouple components of an application, remove direct dependencies so that replacing a component will not have a side effects on the rest of the system. As Dave Thomas explains
a DI application is written as a set of loosely coupled components. These components contain no knitting code: nothing in the application code itself is responsible, for example, for making sure that the necessary objects somehow get an instance of the database connection. Instead, the components all run in a container. This container is given a description of the knitting to be done (typically using an XML file). The container then instantiates objects and sets them into components that need them
I’m new to the language and there maybe a more “pythonic” way to handle inversion of control than using a container. Here is small and contrived example of inversion of control using Pinsor, a IoC container in Python. Those coming from a .NET or Java background will find Pinsor easy to use, but slightly lacking in features.
Related posts:





Looks like it was inspired by Castle Windsor
Ben Scheirman - 25 Aug 09 at 5:01 pm
[...] previous discussion on Inversion of Control raised some questions so I want to take a step back and discuss Dependency Injection. Dependency [...]
Dependency Injection at Shey’s Rebellion - 18 Jan 10 at 10:37 pm