473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

the first arg to super() must be a type, not a class obj?

On p.282 of "Python Cookbook" and in the Python docs on calling super:
http://www.python.org/download/relea...o/#cooperation

it is clear that the first argument to super is a class and not a type.
However, for the code below, I am getting an error when attempting to
provide a class as my first argument and don't understand why. Also,
since this is my first attempt at writing anything of any seriousness
in Python, any other feedback is welcome.

from ftputil import *
import re

from urlparse import urlparse

class ftputilx(FTPHost):
parms = {
'user': '',
'pass': '',
'site': '',
'path': '',
'file': '',
'action': '',
'lcd': '',
'autogo': True,
'debuglevel': 0,
'type': 'b'
}

def bindparms(self, **kwargs):
for k, v in kwargs.items():
self.parms[k] = v

def __init__(self, url, **kwargs):
_s, site, self.parms['path'], _p, _q, _f = urlparse(url)
if '@' in site:
rxs = r'(.+):(.+)@(.+)'
rxc = re.compile(rxs)
rxm = rxc.match(site)
(kwargs['user'],kwargs['pass'],kwargs['site']) =
rxm.group(1), rxm.group(2), rxm.group(3)
self.bindparms(**kwargs)
super(ftputilx, self).__init__()
if __name__ == '__main__':
ftp =
ftputilx("ftp://anonymous:an*******@ftp.kernel.org/pub/linux/")
print ftp.listdir(ftp.curdir)

Sep 7 '06 #1
3 1650
metaperl wrote:
On p.282 of "Python Cookbook" and in the Python docs on calling super:
http://www.python.org/download/relea...o/#cooperation

it is clear that the first argument to super is a class and not a type.
However, for the code below, I am getting an error when attempting to
provide a class as my first argument and don't understand why. Also,
since this is my first attempt at writing anything of any seriousness
in Python, any other feedback is welcome.
"super" only works for new-style classes.

You could make "ftputilx" new-style by inheriting from object and FTPHost,
but FTPHost is still old-style, and I don't know if that's okay with super.

So in your case it would be advisable to use

FTPHost.__init__(self)

instead of

super(ftputilx, self).__init__()

Georg
Sep 8 '06 #2
metaperl wrote:
On p.282 of "Python Cookbook" and in the Python docs on calling super:
http://www.python.org/download/relea...o/#cooperation

it is clear that the first argument to super is a class and not a type.
However, for the code below, I am getting an error when attempting to
provide a class as my first argument and don't understand why. Also,
since this is my first attempt at writing anything of any seriousness
in Python, any other feedback is welcome.
I believe it needs to be a class whose ultimate ancestor is "object",
and not an "old-style" class. This is probably why the docs suggest a
type is required.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Sep 8 '06 #3
Andre Meyer wrote:
Another thing: how does super() work wrt. multiple inheritance? It seems
like it returns only the first superclass.
The whole point of super is that it returns the first superclass in the
MRO that *follows* the class of the (first) argument. It's this
behaviour that makes super() useful in multiple inheritance situations
(if you believe that super() is in fact useful - there are those who
have their doubts).

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Sep 8 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kerim Borchaev | last post by:
Hello! Always when I use "super" I create a code duplication because class used as first arg to "super" is always the class where the method containing "super" was defined in: ''' class C:...
0
by: Delaney, Timothy C (Timothy) | last post by:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195 This is a new version of super that automatically determines which method needs to be called based on the existing stack frames....
6
by: Steven Bethard | last post by:
When would you call super with only one argument? The only examples I can find of doing this are in the test suite for super. Playing around with it: py> class A(object): .... x = 'a'...
9
by: Mike Krell | last post by:
I'm reading Alex Martelli's "Nutshell" second edition. In the section called "Cooperative superclass method calling", he presents a diamond inheritance hierachy: class A(object): def...
4
by: ddtl | last post by:
Hello everybody. Consider the following code: class A(object): def met(self): print 'A.met' class B(A): def met(self):
2
by: Chris Mellon | last post by:
I see super documented, and in use, as below (from the Python documentation) class C(B): def meth(self, arg): super(C, self).meth(arg) I'd like to not write C all the time, so is there any...
10
by: Finger.Octopus | last post by:
Hello, I have been trying to call the super constructor from my derived class but its not working as expected. See the code: class HTMLMain: def __init__(self): self.text = "<HTML><BODY>";...
2
by: huiling25 | last post by:
I was given the pseudo code.. but i still cannot figure out how to do it... how can i find if the vertices are adjacent to the vertex on stack top? I know i have to have an array of true/false (to...
1
by: ssecorp | last post by:
>>super(object, type) <super: <class 'object'>, <type object>> <super: <class 'type'>, <type object>> how can both work? they can't both be the superclass of each other right? or is it some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.