468,305 Members | 1,510 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,305 developers. It's quick & easy.

Subclassing zipfile (new style class)

I'm trying to learn about subclassing new style classes and the first project I
went to do needs to subclass zipfile to add some methods.
Why does this:

import zipfile
class walkZip(zipfile):
pass
if __name__ == "__main__":
print "Hello World"

Traceback (most recent call last):
File "<string>", line 192, in run_nodebug
File "<module1>", line 2, in <module>
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
>>>
Thanks in advance.

-Larry
Sep 6 '07 #1
3 1252
Larry Bates wrote:
import zipfile
class walkZip(zipfile):
pass
if __name__ == "__main__":
print "Hello World"

Traceback (most recent call last):
File "<string>", line 192, in run_nodebug
File "<module1>", line 2, in <module>
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
In your code 'zipfile' is a module, not a class, so you cannot inherit
from it. I believe this is what you are trying to accomplish:

class walkZip(zipfile.ZipFile):
pass

-Farshid
Sep 6 '07 #2
On Thursday 06 September 2007 16:15, Larry Bates wrote:
I'm trying to learn about subclassing new style classes and the first
project I went to do needs to subclass zipfile to add some methods.
Why does this:

import zipfile
class walkZip(zipfile):
pass
if __name__ == "__main__":
print "Hello World"

Traceback (most recent call last):
File "<string>", line 192, in run_nodebug
File "<module1>", line 2, in <module>
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
I think because you need to do this:

from zipfile import ZipFile
class walkZip(ZipFile):
pass
-Tom
Sep 6 '07 #3
import zipfile
class walkZip(zipfile):
pass

if __name__ == "__main__":
print "Hello World"

`zipfile' is the name of the module, not a class. What you probably
want is this:

Expand|Select|Wrap|Line Numbers
  1. import zipfile
  2. class WalkZip(zipfile.ZipFile):
  3. pass
  4.  
  5. if __name__ == "__main__":
  6. print "hello world"
  7.  
Matt

Sep 6 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jacek Generowicz | last post: by
2 posts views Thread by Fuzzyman | last post: by
6 posts views Thread by gregory lielens | last post: by
6 posts views Thread by Bennie | last post: by
6 posts views Thread by Steven D'Aprano | last post: by
2 posts views Thread by stewart.midwinter | last post: by
8 posts views Thread by =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B | last post: by
5 posts views Thread by Neil Crighton | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.