Reasoning behind `from ... import ...` syntax in Python

No idea why it was actually done that way but it's the way I'd do it, simply because, being an engineering type, it seems more natural to me to start from a general category and drill down to specifics.

It would also mean the parser would have to store less stuff if processing sequentially. With:

import x, y, z from a

you have to remember x, y and z. With:

from a import x, y, z

you only have to remember a.


That's why I had so much trouble when I first encountered Perl's post-if variant:

$x = $y if $y > 40;

since you don't know in advance whether what you're reading is conditional or not.


A very wild guess and probably totally non-sense, but I knew that syntax from Modula-2 (man, that was twenty years ago, I feel old)... maybe Python was inspired by it ?


I don't know the complete heritage of this syntax, as it dates from Python 1.x days. But I find it useful to be able to scan down the left side of the source, and quickly find the module names that a script depends on. If a statement read "import a,b,c,d,e,really_long_name, alsdf,lsdf from blah", it would take me a while to find that this script depended on blah.