Reasoning behind `from … import …` syntax in Python

后端 未结 8 1548
刺人心
刺人心 2020-12-18 20:35

I always wondered why the syntax for importing specific objects from a module is from module import x, y, z instead of import x, y, z from module.

8条回答
  •  心在旅途
    2020-12-18 21:29

    It might make more sense in english to say import x, y, z from module but in programming it makes much more sense to bring the more general Item first and then bring the details. It might not be the reason but it makes things easier for the compiler or interpreter. Try writing a compiler and you'll know what I mean :D

提交回复
热议问题