M
metaperl
On p.282 of "Python Cookbook" and in the Python docs on calling super:
http://www.python.org/download/releases/2.2.3/descrintro/#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:[email protected]/pub/linux/")
print ftp.listdir(ftp.curdir)
http://www.python.org/download/releases/2.2.3/descrintro/#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:[email protected]/pub/linux/")
print ftp.listdir(ftp.curdir)