C
C GIllespie
Dear All,
I have a class the looks something like this:
class file:
def __init__(self):
pass
def file2ps(self):
return 'ps'
def file2jpg(self):
return 'jpg'
def file2gif(self):
return 'gif'
etc
What is a quick way of generating all these methods? I'm thinking along the
lines of:
class file:
formats=['ps', 'ps2', 'hpgl', 'pcl', 'mif', 'pic', 'gd', 'gd2', 'gif',
'jpg']
def __init__(self):
for frmt in self.formats:
self.__setattr__('file2'+frmt, ???)
I've tried a variety of things where ??? is, but with no success.
Any ideas?
Thanks
Colin
I have a class the looks something like this:
class file:
def __init__(self):
pass
def file2ps(self):
return 'ps'
def file2jpg(self):
return 'jpg'
def file2gif(self):
return 'gif'
etc
What is a quick way of generating all these methods? I'm thinking along the
lines of:
class file:
formats=['ps', 'ps2', 'hpgl', 'pcl', 'mif', 'pic', 'gd', 'gd2', 'gif',
'jpg']
def __init__(self):
for frmt in self.formats:
self.__setattr__('file2'+frmt, ???)
I've tried a variety of things where ??? is, but with no success.
Any ideas?
Thanks
Colin