PyWart: Module access syntax
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jan 12 01:53:27 EST 2013
On Fri, 11 Jan 2013 21:46:36 -0800, Rick Johnson wrote:
> On Friday, January 11, 2013 10:40:36 PM UTC-6, Chris Angelico wrote:
>> On Sat, Jan 12, 2013 at 3:34 PM, Rick Johnson
>
>> > *The problem:*
>> > ... is readability. The current dot syntax used ubiquitously in paths
>> > is not conveying the proper information to the reader, and in-fact
>> > obfuscating the code.
>>
>> Please explain how this is a problem.
>
>
> What is this importing?
>
> "import lib.gui.simpledialog"
>
> ...is that the "simpledialog module" or "SimpleDialog object"?
It has to be the first, because:
- you can't import members of modules directly using dot syntax
("import math.cos" will fail)
- and it can't be SimpleDialog, because Python is case-sensitive and you
wrote simpledialog.
But ignoring the import, and just looking at the dotted name:
lib.gui.simpledialog
who cares what simpledialog happens to be? So long as you know the
expected interface (say, "it's a callable object that takes three
arguments"), you can use it the same way whether it is a function, a
method, a class or something else. The implementation could change, and
you need not care.
If you actually do care what the type of simpledialog is, you can find
out easily:
type(lib.gui.simpledialog)
--
Steven
More information about the Python-list
mailing list