472,344 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,344 software developers and data experts.

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 1412
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jacek Generowicz | last post by:
The Numeric docs state that "Subclassing Numeric arrays is not possible due to a limitation of Python." What is this limitation? My first guess...
2
by: Fuzzyman | last post by:
I recently went through a bit of a headache trying to subclass string.... This is because the string is immutable and uses the mysterious __new__...
6
by: gregory lielens | last post by:
Hello, I am currently writing python bindings to an existing C++ library, and I just encountered a problem that I hope has been solved by more...
6
by: Bennie | last post by:
Hi, I have a problem with ZipFile. It works okay untily I come across a file that is greater then 1Gb. Then it exit with the error:...
6
by: Steven D'Aprano | last post by:
I've been working with the Borg design pattern from here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 and I'm having problems...
2
by: stewart.midwinter | last post by:
I've been experimenting with the python zipfile module, and have run into a snag. I'm able to create a new zipfile with the module's ZipFile...
3
bvdet
by: bvdet | last post by:
Following is an example that may provide a solution to you: """ Function makeArchive is a wrapper for the Python class zipfile.ZipFile 'fileList'...
8
by: =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B | last post by:
I made a C/S network program, the client receive the zip file from the server, and read the data into a variable. how could I process the zipfile...
5
by: Neil Crighton | last post by:
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.