1

The [docs] say:

6.4.1. Importing * From a Package

Now what happens when the user writes from sound.effects import *? Ideally, one would hope that this somehow goes out to the filesystem, finds which submodules are present in the package, and imports them all. This could take a long time and importing sub-modules might have unwanted side-effects that should only happen when the sub-module is explicitly imported.

What does "might have unwanted side-effects" mean?

user3156459
  • 1,123
  • 2
  • 9
  • 17
  • I think it may be due to loosing the "where" function/classes are from: if you have 2 different `from x import *`, function/classes names can be overwritten and everything just breaks – DecowVR Mar 21 '22 at 12:40
  • 1
    Python will evaluate and run a module the first time you import it. If there's any code with side effects in the module (for example `print()` calls) those will happen. Read the answers to this question to see some examples: https://stackoverflow.com/questions/6523791/why-is-python-running-my-module-when-i-import-it-and-how-do-i-stop-it – Håken Lid Mar 21 '22 at 12:56
  • @HåkenLid, thanks, the examples are helpful. I'm still confused by the wording of the docs "...might have unwanted side-effects that should only happen...". Why the *unwanted* side-effects are expected (should) happen? – user3156459 Mar 21 '22 at 13:28
  • If you mean `from x import *`, this will import all the modules in that package -> hard to debug since ydk where it all comes from. – BrainFl Mar 22 '22 at 09:26
  • @HåkenLid, the links you provided do explain the confusion; and if you make this the answer, I will accept it. Or close this question as a duplicate. – user3156459 Mar 22 '22 at 13:36

0 Answers0