How Do I Deal With Error While Importing In Python
I have got 2 modules which tend to import each other because they will be using each other in classes. I found in this link which tells to use try/except statement along with impor
Solution 1:
I have got 2 modules which tend to import each other because they will be using each other in classes
Then you have a design issue, and the proper solution is not hack around it but to solve this design issue. Having circular dependencies between modules is a big no no whatever the language, even when it's technically possible.
You have three possible solutions here, depending on the concrete case: extracting common deps to a third module, regrouping both modules in one, and using dependency injection. But by all means avoid the temptation to resort to ugly hacks that will cause various issues later on (been here, done that :-/
, now I know better).
Post a Comment for "How Do I Deal With Error While Importing In Python"