class 'Exception', unable to use 'super' to call superclass initializer
Hi,
environment: Python 2.4, GNU/Linux, kernel 2.6.12.2
having subclassed 'Exception' I'm trying to call the initialiser
__init__(...) of the superclass Exception with 'super(..).__init__(..)' .
However, trying to do so results in a
'TypeError: super() argument 1 must be type, not classobj'.
Now, if I use 'Exception.__init__(..)' instad of super(..)... ,everything
works just as one would expect.
Why does 'super(..).__init__(..)' fail?
thank you for any suggestions
chriss
Here is some example code to illustrate the point:
class WorkingException(Exception):
def __init__(self, message):
# works as I would expect
Exception.__init__(self, message)
class BrokenException(Exception):
def __init__(self, message):
# fails with a typeError
super(BrokenException, self).__init__(self, message)
# - case 1 -
try:
raise WorkingException("Hello WorkingException")
except WorkingException, e:
print e
# - case 3 -
try:
raise BrokenException("Hello BrokenException")
except BrokenException, e:
print e
--
http://mail.python.org/mailman/listinfo/python-list
Re: calling command line programs?
Grant Edwards wrote: > On 2005-09-11, Yevgeniy (Eugene) Medynskiy <[EMAIL PROTECTED]> wrote: > >> This is probably a very newbie question, but after searching >> google and docs @ python.org I can't find an answer, so maybe >> someone would be able to help? >> >> I'd like to call command-line functions from my python script >> (like you would in perl using backticks)... Is there a way of >> doing this? And if so, how does the environment get treated (I >> have some variables in my env that the programs I'd be calling >> need to see). > > Take a look at os.popen, os.spawn, or the popen2, and > subprocess modules. > > That last one seems to be gaining popularity. > The suggested modules and functions have been deprecated according to the python 2.4 docs. The doc suggests to use the functions in the 'subprocess' module. chriss -- http://mail.python.org/mailman/listinfo/python-list
Re: class 'Exception', unable to use 'super' to call superclass initializer
Peter Hansen wrote: > chriss wrote: >> Hi, >> >> environment: Python 2.4, GNU/Linux, kernel 2.6.12.2 >> >> having subclassed 'Exception' I'm trying to call the initialiser >> __init__(...) of the superclass Exception with 'super(..).__init__(..)' . >> However, trying to do so results in a >> 'TypeError: super() argument 1 must be type, not classobj'. >> >> Now, if I use 'Exception.__init__(..)' instad of super(..)... ,everything >> works just as one would expect. >> >> Why does 'super(..).__init__(..)' fail? > > Exceptions do not inherit from 'object'; they are old-style classes. > > super() can be used only with new-style classes (which subclass 'object'). > > -Peter That explains it all right. Thank you very much for your answer. chriss -- http://mail.python.org/mailman/listinfo/python-list
Re: calling command line programs?
Grant Edwards wrote: > On 2005-09-10, chriss <[EMAIL PROTECTED]> wrote: > >>> Take a look at os.popen, os.spawn, or the popen2, and >>> subprocess modules. >>> >>> That last one seems to be gaining popularity. >> >> The suggested modules and functions have been deprecated according to the >> python 2.4 docs. The doc suggests to use the functions in the >> 'subprocess' module. > > The subprocess module is depricated? > no, the subrocess module intends to replace modules and functions such as: os.system os.spawn* os.popen* popen2.* commands.* have a look at http://python.org/doc/2.4.1/lib/module-subprocess.html -- http://mail.python.org/mailman/listinfo/python-list
