Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Inheritance
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nancy  
View profile  
 More options Jul 10 2012, 1:15 pm
From: Nancy <eclecticna...@gmail.com>
Date: Tue, 10 Jul 2012 10:15:18 -0700 (PDT)
Local: Tues, Jul 10 2012 1:15 pm
Subject: Inheritance

I'm experimenting with inheritance and could use some guidance.

Here's what I have, after fighting off error messages on previous attempts.
:-)

import ftplib
class myftp(ftplib.FTP):
    def __init__(self):
        self.FTP = ftplib.FTP()    

This appears to do what I want it to do* (see below).
But should I be setting it up differently than shown above?

*As an example, I can do the following and it works.

ftp = myftp()
ftp.connect(host)
ftp.login(user, passwd)
# etc
ftp.close()

Thanks for any input, thanks!
-Nancy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jay Wren  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 1:30 pm
From: Jay Wren <jrw...@gmail.com>
Date: Tue, 10 Jul 2012 13:30:03 -0400
Local: Tues, Jul 10 2012 1:30 pm
Subject: Re: Inheritance

That works, but you are allocating and initializing the FTP member and never using it.

import ftplib
class myftplib(ftplib.FTP):
    def __init__(self):
        pass

would work just the same, and for that matter, so would:

class myftplib(ftplib.FTP):
  pass

--

On Jul 10, 2012, at 1:15 PM, Nancy wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Burns  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 2:14 pm
From: Ryan Burns <rdbu...@gmail.com>
Date: Tue, 10 Jul 2012 14:14:29 -0400
Local: Tues, Jul 10 2012 2:14 pm
Subject: Re: Inheritance

If you wanted to pass some of your own arguments to your own init and also
use the original init you can also do that:

import ftplib
class MyFTPLib(ftplib.FTP):
   def __init__(self,custom,host):
      ftplib.FTP.__init__(self,host)
      self.custom = custom

This stackoverflow thread has some more discussion about this kind of thing:
http://stackoverflow.com/questions/576169/understanding-python-super-...

I'm sure you can also take a variable number of arguments to match the FTP
init precisely, I think you would say something like *args and then pass
that to the FTP init?

- As an aside, the Python style
guide<http://www.python.org/dev/peps/pep-0008/>recommends using
CapWords for class names.

--
about.me/ryanburns

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Woolcock  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 1:26 pm
From: Paul Woolcock <pwool...@gmail.com>
Date: Tue, 10 Jul 2012 13:26:36 -0400
Local: Tues, Jul 10 2012 1:26 pm
Subject: Re: Inheritance

It would be better to use `super` instead:

    import ftplib
    class MyFTP(ftplib.FTP):
        def __init__(self):
            super(MyFTP, self).__init__()

Here is the python documentation on `super`:
http://docs.python.org/library/functions.html?highlight=super#super

--
Paul Woolcock
Twitter @pwoolcoc
Github @pwoolcoc

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nancy  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 2:57 pm
From: Nancy <eclecticna...@gmail.com>
Date: Tue, 10 Jul 2012 11:57:03 -0700 (PDT)
Local: Tues, Jul 10 2012 2:57 pm
Subject: Re: Inheritance

I appreciate the feedback! So far, now, I have:

import ftplib
class MyFTP(ftplib.FTP):
    def __init__(self):
        pass

I do plan to do some "custom" but am not there yet :)

I did try this (in place of "pass"):  super(MyFTP, self).__init__()
TypeError: super() argument 1 must be type, not classobj

Thanks again,
-Nancy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nancy  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 3:02 pm
From: Nancy <eclecticna...@gmail.com>
Date: Tue, 10 Jul 2012 15:02:16 -0400
Local: Tues, Jul 10 2012 3:02 pm
Subject: Re: Inheritance

Also I should have mentioned (though don't think it's been a factor yet):

Py 2.6 on Win

-Nancy
On Jul 10, 2012 2:57 PM, "Nancy" <eclecticna...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Burns  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 3:11 pm
From: Ryan Burns <rdbu...@gmail.com>
Date: Tue, 10 Jul 2012 15:11:24 -0400
Local: Tues, Jul 10 2012 3:11 pm
Subject: Re: Inheritance

I tried this exact code;

import ftplib
class MyFTP(ftplib.FTP):
    def __init__(self):
        super(MyFTP,self).__init__()

And it didn't throw any errors.  A quick google indicated this error can
occur if the parent class you are inheriting from is not a new-style class.
 I'm not sure why that would be the case in your case, although I am on
2.7.

--
about.me/ryanburns

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Burns  
View profile  
 More options Jul 10 2012, 3:18 pm
From: Ryan Burns <rdbu...@gmail.com>
Date: Tue, 10 Jul 2012 15:18:32 -0400
Local: Tues, Jul 10 2012 3:18 pm
Subject: Re: Inheritance

Ahaha, the ftplib.FTP class is an old style class in the 2.6 release.

Huh, I checked both the 2.6.8 and 2.7.3 ftplib source and it's an old style
class in both.  I'm not sure why it worked for me.

You can still use ftplib.FTP.__init__(self)      - super() only really
matters if you have multiple inheritance (feel free to disabuse me of that
notion if it's not the case).

-Ryan

--
about.me/ryanburns

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ryan Burns  
View profile  
 More options Jul 10 2012, 3:23 pm
From: Ryan Burns <rdbu...@gmail.com>
Date: Tue, 10 Jul 2012 15:23:01 -0400
Local: Tues, Jul 10 2012 3:23 pm
Subject: Re: Inheritance

Oh, it worked for me because I didn't create an instance of MyFTP when I
tested it, and that is of course when the error occurs.

Long story short: you can't use super() if you're inheriting from
ftplib.FTP in that version of Python, but in general it's the way to go.

--
about.me/ryanburns

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nancy  
View profile   Translate to Translated (View Original)
 More options Jul 10 2012, 4:11 pm
From: Nancy <eclecticna...@gmail.com>
Date: Tue, 10 Jul 2012 16:11:27 -0400
Local: Tues, Jul 10 2012 4:11 pm
Subject: Re: Inheritance

I appreciate the clarification on super() - Thanks!
On Jul 10, 2012 3:23 PM, "Ryan Burns" <rdbu...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »