-4

If my foo.py is merely foo_var = 1 and bar.py is merely import foo, I know I can write baz.py that says from bar import foo_var, but should I? (Or should I instead do from foo import foo_var?)

Is there any reason why chaining imports like this would be bad?

2
  • 1
    Suggested read towardsdatascience.com/…
    – Rub
    Dec 26, 2022 at 11:03
  • This read did not help me answer my question. This is about the difference between import X and from X import Y, not whether I should import from the original declaring module or from modules that imported from that original module instead.
    – Pro Q
    Jan 13, 2023 at 3:34

1 Answer 1

2

No, it's fine. The first (from bar ...) compiles and runs both foo.py and bar.py while the latter (from foo ...) only compiles and runs foo.py, but if bar.py only contains import foo, the overhead is negligible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.