PyWart: Module access syntax

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Jan 14 12:34:56 EST 2013


On Sun, 13 Jan 2013 21:22:57 -0800, Rick Johnson wrote:

> On Saturday, January 12, 2013 12:45:03 AM UTC-6, Steven D'Aprano wrote:
>> On Fri, 11 Jan 2013 20:34:20 -0800, Rick Johnson wrote:
>> > [...]
>> So what do you do for, say, os.path? According to the first rule, you
>> must write it as os:path because path is a module; according to the
>> second rule, you must write it as os.path because path is a member of
>> os. So which rule wins?
> 
> Since "path" is an identifier in the module "os" that points to a system
> specific module (which is loaded at run-time), you would access os.path
> just as you do today; using the dot. No changes here. Next!

Here you say that os.path will not change. But later in your post, you 
say:


> the programmer will need to be sure he places a colon
> between modules. Which means a programmer will need to know which path
> members are modules and which are objects

Since both os and path are modules, you here say that they need a colon 
between them. This contradicts the above when you say the syntax for 
os.path won't change.

If even you don't understand your own proposal, how do you expect anyone 
else to understand it?

Perhaps you should start by explaining, unambiguously and IN FULL, under 
what circumstances the programmer will need to use your : syntax.

To start:

os.path or os:path

json.scanner or json:scanner



> I said it before and i'll say it again: If you don't know if your calls
> are accessing module space or object space (be it instanced object or
> static object), then you are sadly informed

"Sadly informed"? Dr Freud called, he wants his slip back.

Modules are objects, and there is no difference between module space and 
object space, except that Python provides a convenience syntax for 
members of the current module. Modules are instances of a class, just 
like ints, strings, lists, and everything else.


py> from types import ModuleType
py> type(ModuleType) is type(int)
True

py> hasattr(os, '__dict__')
True


[...]
> Wait, "classes" are NOT objects.

They certainly are. Classes are created at runtime, they have a type -- 
the class of a class is the metaclass. You can even customize class 
behaviour with metaclass programming.

Perhaps you are thinking about some other language, like Java, which 
fails to have first-class classes (pun intended).


-- 
Steven



More information about the Python-list mailing list