Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22933

Brian Okken: Fixing Circular Imports in Python with Protocol

$
0
0
The problem started when I had two classes that needed to talk to each other. Sometimes, classes need to talk to each other in both directions. The following example is made up, but mostly behaves like the original problem. Let’s say I have a Director and an Actor. The Director tells the Actor to do_action(). In order to do the action, the Actor needs to get_data() from the Director. Here’s our director.

Viewing all articles
Browse latest Browse all 22933

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>