On Fri, 24 Sep 2004 21:04:52 -0400, Dan Sugalski wrote:

> At 7:51 PM -0400 9/24/04, Jonathan Polley wrote:
>>On Fri, 24 Sep 2004 14:04:52 -0400, Dan Sugalski wrote:
>>
>>>  ...
>>>  (Though class names/namespaces seem to be separate)
>>>  ...
>>
>>I think Guido might have made things a bit harder to separate out than you
>>anticipate, unless I misread you. It appears that modules and classes are
>>also imported into the same namespace as everything else in python.
> 
> Yeah, I had that pointed out in private mail. At this point I'm a 
> half-step away from going fully unified. One thing though:
> 
> What happens if you then do something like "import foo" and the foo 
> module has a "class a:" definition in it?

I'm not exactly sure how I became the python expert.  I've only been
using it since July.  Glad to be of service, though.

-- foo.py:
class a:
    member = 0

-- interactive python session:
>>> import foo
>>> dir()
['__builtins__', '__doc__', '__name__', 'foo']
>>> dir(foo)
['__builtins__', '__doc__', '__file__', '__name__', 'a']
>>> dir(foo.a)
['__doc__', '__module__', 'member']
>>> type(foo)
<type 'module'>
>>> type(foo.a)
<type 'classobj'>
>>> type(foo.a.member)
<type 'int'>

So the class acts pretty much the same as a module as far as namespaces
go, at least to my untrained eye.

I also think you can do some funnybusiness with having a class have a
magic function that gets called when people try to access foo.blah so that
you can have transparent method call behavior, but I do not know how that
works.  (That's kind of like what tied hashes are, right?  I've never done
that sort of thing in perl, either.)

By the way, this isn't the list for it, but it would be cool if perl6 had
an interactive mode as good as python's.  It's one of the few places I
think python has a compelling lead.

-- 
Jonathan

Reply via email to