[Zope-dev] urg

Martijn Faassen faassen@vet.uu.nl
Tue, 7 Mar 2000 12:54:22 +0100


Tom Deprez wrote:
> Ok, it was the import problem! Thanks to all!

Following this thread with baited breath. Ah, I would've said the same
as Rik did, ain't I good? (it's easy to say so in retrospect) :)

> Q1: So, in python you've to say which class you want to import? 

In Python, namespaces are _the_ thing. If you have a module A (called
A.py in the filesystem), and it's somewhere where Python can see it
(so it'll import it), and module A contains something called B (this
may be a class, some global variable, a function, whatever), you
can do this: 

import A  # now this module knows about module A

A.B() # do something with B in A

Or you can do this:

from A import B # import B into this namespace directly, from A

B() # do something with B

Or you can even do this:

import A
from A import B

A.B()
B()

The Python tutorial at www.python.org should explain this.

> Q2: And from test.parent.mylib means go to the directory test then parent
> and then use the mylib library?

Python has a package system. If you have a directory which contains a
file (may be empty) called __init__.py, this directory becomes a package.
A package may contain multiple modules (or more packages).

Because you use the dot notation (.) to refer to something inside another
namespace, A.B.C may mean various things. You may be referring to a function
or global or class C in module B which is in package A. You may be referring
to a function C in object B which is in object A, too.

> However, now I stumbeld on more problems. I receive an error about using an
> onbound method... 
> 
> Q3: What is an unbound method??

Python objects can have methods attached to them. For instance:

class Foo:
    def mymethod(self):
        print "Hoi"

Now if I do:

m = Foo.mymethod

and then:

m()

I'll get an unbound method error, as I'm trying to treat a method (to some
class) as a function, and Python doesn't know what to do there, because
it doesn't make sense (usually) to a call a method on a class directly.

If you do this:

foo = Foo() # create a foo object
n = foo.mymethod

and then:

n()

It'll work, though, as Python knows to which object this method is bound
(foo).

[snip] 
> Now, adding an instance works without a problem, but when a try to cut and
> paste the instance, I get the following message:
> 
> Zope Error
> 
>   Zope has encountered an error while publishing this resource. 
>  
>    Error Type: AttributeError
>    Error Value: aq_acquire

> Q4: Euhm, what does this error means?

Uh oh -- that's hard to say, as we're dealing with Zope's sometimes rather
mysterious acquisition machinery here.. Zope wraps objects into
'acquisition wrappers'. These wrapper objects behave exactly like the
wrapped objects, but define some extra machinery to handle acquisition.
What it looks like here is your object somehow lost its wrappers, so Zope
sees a wrapperless object where it expects a wrapped one.

Regards,

Martijn