Serdar Tumgoren wrote:
def add_name(self):
try:
self.name = SPECIALIZED_SQLcall_for_child()
except SpecialSQLError:
#default to the superclass's add_name method
super(Child, self).add_name()
That certainly is a lot easier to read. So if I were to
> def add_name(self):
> try:
> self.name = SPECIALIZED_SQLcall_for_child()
> except SpecialSQLError:
> #default to the superclass's add_name method
> super(Child, self).add_name()
>
That certainly is a lot easier to read. So if I were to go that route,
wo
> In this case, is there any argument against checking for None? Or is
> it better to do a type check for a string?
>
> if name is None:
> super()
> else:
> # do stuff
That might be ok if string or None are the only types you could get.
Checking for not string will catch any number
>>> self.name =ame
>
> I assume this is a typo? And it never gets executed because the error is
> always raised.
yep. that was a typo that should be "name"
> I don't mind using exceptions for a simple test but not where the test is
> being forced by a piece of code that does nothing. I
Serdar Tumgoren wrote:
An "if" test would be more readable, I agree. But I was trying to
apply the "Easier to Ask Permission Forgiveness" style, discussed in
the Python Cookbook: ,
Err..."Easier to Ask Forgiveness than Permission" approach is what I
meant (perhaps proving my point about n
"Dave Angel" wrote
def result_of_SPECIALIZED_SQLcall_for_child():
name =None
return name
I assume this is a placeholder for more complex code to follow?
class Child(Parent):
def add_name(self):
name = result_of_SPECIALIZED_SQLcall_for_child()
try:
na
> An "if" test would be more readable, I agree. But I was trying to
> apply the "Easier to Ask Permission Forgiveness" style, discussed in
> the Python Cookbook: ,
>
Err..."Easier to Ask Forgiveness than Permission" approach is what I
meant (perhaps proving my point about not fully understanding t
> I know this is a simplified example, but I'd still like to point out that
> using exceptions when there's a simple test is not reasonable. You can
> just check for None with a simple if test.
An "if" test would be more readable, I agree. But I was trying to
apply the "Easier to Ask Permission
Serdar Tumgoren wrote:
def result_of_SPECIALIZED_SQLcall_for_child():
name =None
return name
class Child(Parent):
def __init__(self):
super(Child, self).__init__()
def add_name(self):
name = result_of_SPECIALIZED_SQLcall_for_child()
try:
> I know that when you need super(), you have to use it everywhere. So I
> would stick with what you have.
>
> Kent
>
Okay. Thanks as always to all.
Best,
Serdar
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http:
On Tue, Sep 22, 2009 at 2:20 PM, Serdar Tumgoren wrote:
> Is my case isolated enough here that I could use the old syntax, but
> leave my remain usages of super in tact? My worry is that I'd have to
> convert all of my subclasses (quite a few at this point) to the
> old-style...
I know that when
> I prefer the older approach too, it is simple and explicit. super()
> comes with a raft of complications (google "super considered harmful")
> and AFAIK it is only really needed in the case of "diamond"
> inheritance.
>
The explicit method does indeed seem...well...more explicit and easier
to und
On Tue, Sep 22, 2009 at 1:27 PM, Alan Gauld wrote:
> I tend to prefer the explicit approach since it is explicit which
> class/method is getting called, but I suspect the preferred mechanism
> nowadays is to use super()
I prefer the older approach too, it is simple and explicit. super()
comes wi
"Serdar Tumgoren" wrote
Is there a way to call a superclass method after I've overridden it in
a subclass?
Yes, you can do it as you have iin __init__ using super()
class Child(Parent):
def __init__(self):
super(Child, self).__init__()
Or you can do it explicitly:
Par
> You're actually already doing it: look at __init__.
>
> __init__ is overridden in your subclass, so you call super(Child,
> self).__init__() to initialise the class using the parent
> (superclass)'s __init__ method.
Yes indeed. Thanks for pointing it out. In case it helps anyone else
out down t
Hi everyone,
Is there a way to call a superclass method after I've overridden it in
a subclass?
Specifically, what I'm trying to is something like the following:
class Parent(object):
def add_name(self):
self.name = result_of_GENERIC_SQLcall()
class Child(Parent):
def __init__(se
16 matches
Mail list logo