import in code

Cameron Simpson cs at cskk.id.au
Mon Jul 23 03:52:10 EDT 2018


On 22Jul2018 15:38, Mark Lawrence <breamoreboy at gmail.com> wrote:
>On 22/07/18 05:45, Cameron Simpson wrote:
>>Circular imports: 2 codependent modules. If you have:
>>
>>  module A:
>>    import B
>>  module B:
>>    import B
>>
>>That won't work: the second import (whichever it turns out to be) 
>>will fail. One workaround is to make one of the modules put off the 
>>import. A better approach is usually to redesign things so that they 
>>don't do a mutual import (move classses etc around, or merge them). 
>>This is always feasible, but often is.
>
>I don't ever recall seeing a module try to import itself, but then 
>perhaps you meant module B should be importing module A? :)

Yes, sorry. Poor proof reading. - Cameron


More information about the Python-list mailing list