By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,509 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,509 IT Pros & Developers. It's quick & easy.

Subclassing zipfile (new style class)

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.