Python import mechanics

前端 未结 2 954
名媛妹妹
名媛妹妹 2020-11-29 09:15

I have two related Python \'import\' questions. They are easily testable, but I want answers that are language-defined and not implementation-specific, and I\'m also interes

2条回答
  •  臣服心动
    2020-11-29 10:04

    Alan's given a great answer, but I wanted to add that for your question 1 it depends on what you mean by 'imports'.

    If you use the from C import x syntax, then x becomes available in the namespace of B. If in A you then do import B, you will have access to x from A as B.x.

    It's not so much bad practice as potentially confusing, and will make debugging etc harder as you won't necessarily know where the objects have come from.

提交回复
热议问题