PyWart: Module access syntax

Rick Johnson rantingrickjohnson at gmail.com
Fri Jan 11 01:01:37 EST 2013


Python's module/package access uses dot notation. 

  mod1.mod2.mod3.modN

Like many warts of the language, this wart is not so apparent when first learning the language. The dot seems innocently sufficient, however, in truth it is woefully inadequate! Observe:

 name1.name2.name3.name4.name5

Can you tell me which names are modules, which are classes, and which are methods/functions? Wait, i know the argument you'll use:

  """I can decipher from spelling! Modules use all lowercase, classes use initial uppercase, and methods use words_sep_by_underscore. I'm so smart!"""

Indeed. But that's only *_IF_* everybody used the same style guide. And as we know many people don't follow the style guide (not to mention the style guide has issues!) And since style is NOT enforced, we suffer the unintuitive syntax nightmare! The solution is obvious by using proper syntax. 

 import lib:gui:tkinter:dialogs.SimpleDialog as Blah

You /could/ use two colons:
 
 import lib::gui::tkinter::dialogs.SimpleDialog as Blah

...and i think this syntax does help to separate the identifiers more clearly, but since these imports can be quite long, i prefer the single colon myself.



More information about the Python-list mailing list