Johannes Bauer a écrit :
Hello group,

I'm having a seemingly simple problem. I want to generate a hierarchy of modules, like this one:

GenerationScripts/
GenerationScripts/dhcp
GenerationScripts/bind9

And the files:

GenerationScripts/dhcp/__init__.py
GenerationScripts/bind9/generator.py
GenerationScripts/bind9/__init__.py
GenerationScripts/mastergen.py
GenerationScripts/__init__.py

All packages (bind9, dhcp) should inherit from the master generator "mastergen".

Sorry but this makes no sense. inheritance is a class feature - packages and modules don't 'inherit'.

I'm at the very beginning:

$ cat GenerationScripts/__init__.py
import bind9
#import dhcpd

$ cat GenerationScripts/bind9/__init__.py
import GenerationScripts.bind9.generator

$ cat GenerationScripts/bind9/generator.py
from GenerationScripts import mastergen

class generator(mastergen):

<OT>pep08 : class identifiers should be in CamelCase</OT>

    def __init__(self):
        print "init bind9 generator"

here, mastergen is a module object, not a class object. This just can't work. What are you trying to do exactly ???

Now what happens when I import GenerationScripts and try to create a instance of GenerationScripts.bind9.generator is the following:

Traceback (most recent call last):
  File "./Generate.py", line 3, in <module>
    import GenerationScripts
  File "/home/joe/x/GenerationScripts/__init__.py", line 3, in <module>
    import bind9
File "/home/joe/x/GenerationScripts/bind9/__init__.py", line 4, in <module>
    import GenerationScripts.bind9.generator
File "/home/joe/x/GenerationScripts/bind9/generator.py", line 7, in <module>
    class generator(mastergen):
TypeError: Error when calling the metaclass bases
    module.__init__() takes at most 2 arguments (3 given)
>
I really don't get it - and I've searched and found the same problem, read the descirption - but still don't get it. What's happening here?

What's happening is that you try to use a module instance (really: an instance of class 'module') as a base class - and, as a result, the 'module' class as a metaclass. But 1/ the 'module' class initializer's signature is not compatible with a metaclass signature, and 2/ anyway, the 'module' class constructor doesn't return a class object anyway.

I don't know what you trying to do, but I suggest you (re)read the FineManual(tm)'s relevant sections, that is, sections about modules and packages, and sections about Python's 'new-style' object model.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to