On 16/07/19 10:08 PM, אורי wrote:
Hi,
1. When we use super() in Python 3, we don't pass it the first argument
(self). Why?
What happens if the first argument is not self?
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
I think it would make more sense t
[Rearranged and snipped so this makes any kind of sense]
On 16/07/2019 16:43, אורי wrote:
On Tue, Jul 16, 2019 at 3:13 PM Rhodri James wrote:
On 16/07/2019 11:08, אורי wrote:
2. I want to override a function called build_suite in an inherited
class.
The function receives an argument "test_l
lot of the answers to your questions are at least implied
> in the Fine Manual
> (https://docs.python.org/3/library/functions.html#super), but it's not
> very clear and written more for precision than comprehension. Here's my
> attempt at explaining :-)
>
> On 16/07/2019 1
אורי wrote:
Hi,
1. When we use super() in Python 3, we don't pass it the first argument
(self). Why?
Actually the first argument to super() isn't self, it's the class that
we want the superclass of. The *second* argument is self. In the
normal course of using super() ins
Hi,
1. When we use super() in Python 3, we don't pass it the first argument
(self). Why?
What happens if the first argument is not self?
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
I think it would make more sense to use something like
self.super().__init__(
On 10/11/2013 04:33 AM, Ian Kelly wrote:
On Thu, Oct 10, 2013 at 8:11 PM, Steven D'Aprano
>One of the side-effects of this being a hack is that this doesn't work:
>
>class X(Y):
> def method(self, arg):
> f = super
> f().method(arg)
Actually, that works just fine. The
On 10/11/2013 04:11 AM, Steven D'Aprano wrote:
super() with no arguments is*completely* a hack[1], and one where GvR
has said "Never again!" if I remember correctly. I don't think he regrets
allowing the super compile-time magic, just that it really is magic and
he doesn't want to make a habit
On Fri, Oct 11, 2013 at 2:00 PM, Steven D'Aprano
wrote:
> I'll now go and write "I will always test my code snippets before
> posting" on the blackboard one hundred times.
print("I will always test my code snippets before posting\n"*100)
ChrisA
PS. Irony would be having a bug in that because I
On Thu, 10 Oct 2013 20:33:37 -0600, Ian Kelly wrote:
> On Thu, Oct 10, 2013 at 8:11 PM, Steven D'Aprano
> wrote:
>> One of the side-effects of this being a hack is that this doesn't work:
>>
>> class X(Y):
>> def method(self, arg):
>> f = super
>> f().method(arg)
>
> Actually
On Thu, Oct 10, 2013 at 8:11 PM, Steven D'Aprano
wrote:
> One of the side-effects of this being a hack is that this doesn't work:
>
> class X(Y):
> def method(self, arg):
> f = super
> f().method(arg)
Actually, that works just fine. The compiler sees that super is
accessed wi
On Thu, 10 Oct 2013 07:04:38 -0400, Ned Batchelder wrote:
> super() with no args is a kind of hack to begin with. It involves a
> special case in the compiler (so that using the name "super" as a
> function call will act as if you had accessed the name "__class__" so
> that super can find it late
On 10/10/2013 01:04 PM, Ned Batchelder wrote:
On 10/10/13 3:22 AM, Marco Buttu wrote:
>>> import inspect
>>> class B(A):
... def bfoo(*args):
... frame = inspect.currentframe()
... for obj, value in frame.f_locals.items():
... print(obj, value, sep=' --> ')
...
On 10/10/13 3:22 AM, Marco Buttu wrote:
On 10/09/2013 06:47 PM, Ned Batchelder wrote:
>>> class B(A):
... def bfoo(*args):
... super().afoo(*args[1:])
...
>>> B().bfoo(1, 2, 3)
Traceback (most recent call last):
File "", line 1, in
File "", line 3, in bfoo
RuntimeError: super()
On 10/09/2013 06:47 PM, Ned Batchelder wrote:
>>> class B(A):
... def bfoo(*args):
... super().afoo(*args[1:])
...
>>> B().bfoo(1, 2, 3)
Traceback (most recent call last):
File "", line 1, in
File "", line 3, in bfoo
RuntimeError: super(): no arguments
How come?
The no-args s
On 10/9/13 11:44 AM, Marco Buttu wrote:
Given this class:
>>> class A:
... def afoo(*args):
... print(args)
in Python 3 we can write the following class:
>>> class B(A):
... def bfoo(*args):
... super(B, args[0]).afoo(*args[1:])
...
>>> B().bfoo(1, 2, 3)
(<__main__.B ob
Given this class:
>>> class A:
... def afoo(*args):
... print(args)
in Python 3 we can write the following class:
>>> class B(A):
... def bfoo(*args):
... super(B, args[0]).afoo(*args[1:])
...
>>> B().bfoo(1, 2, 3)
(<__main__.B object at 0x7f5b3bde48d0>, 1, 2, 3)
witho
16 matches
Mail list logo