[Chicago] Avoiding circular imports

Adam Yala adamkyala at gmail.com
Sun Jan 8 17:05:04 EST 2017


I'm trying to write a python wrapper for a web api. I have two files,
api.py and models.py. api.py contains a Client class used to make requests
to the web api. models.py contains objects from the web api in python form.

api.py has the line: from models import Company
models.py has the line: from api import Client

The Company class uses the Client class to make other needed web api calls
(like getting Employees). The Client class returns instances of Company
after web api calls.

However, I'm getting circular import errors. Is there a safer way to
implement these imports? I've tried absolute imports and relative imports,
but both throw errors.

If anyone has any guides or good reads on writing web api wrappers, I'd
love to give them a read. My google-fu has failed me on finding good
resources.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20170108/7a0db3d0/attachment.html>


More information about the Chicago mailing list