Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55815 > unrolled thread

Re: Asterisk sign before the 'self' keyword

Started byRobert Kern <robert.kern@gmail.com>
First post2011-02-11 10:10 -0600
Last post2011-02-11 08:57 -0800
Articles 5 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Asterisk sign before the 'self' keyword Robert Kern <robert.kern@gmail.com> - 2011-02-11 10:10 -0600
    Re: Asterisk sign before the 'self' keyword "christian.posta" <christian.posta@gmail.com> - 2011-02-11 08:57 -0800
      Re: Asterisk sign before the 'self' keyword "christian.posta" <christian.posta@gmail.com> - 2011-02-11 08:59 -0800
    Re: Asterisk sign before the 'self' keyword "christian.posta" <christian.posta@gmail.com> - 2011-02-11 08:59 -0800
    Re: Asterisk sign before the 'self' keyword "christian.posta" <christian.posta@gmail.com> - 2011-02-11 08:57 -0800

#55815 — Re: Asterisk sign before the 'self' keyword

FromRobert Kern <robert.kern@gmail.com>
Date2011-02-11 10:10 -0600
SubjectRe: Asterisk sign before the 'self' keyword
Message-ID<mailman.106.1297440619.1633.python-list@python.org>
On 2/11/11 9:06 AM, christian.posta wrote:
> I searched quickly to see whether this may have been discussed before,
> but it's possible my search criteria was not refined enough to get any
> hits. Forgive me if this is a silly question..
>
> I was reading some Python code from a third-party app for the django
> project... i saw this in the code and I wasn't certain what it means,
> nor could I find anything helpful from google.
>
> Within the __call__ function for a class, I saw a method of that class
> referred to like this:
>
> *self.<method_name_here>()
>
> The brackets indicate the method name.
> What does the *self refer to??
> Does it somehow indicate the scope of the 'self' variable?

Can you show the whole statement? Most likely, this was embedded in some other 
call, e.g.:

   foo(*self.method())

If this is the case, the * does not bind to "self"; it binds to all of 
(self.method()), i.e.:

   foo(*(self.method()))

This is just the foo(*args) syntax that unpacks a tuple into individual 
arguments to pass to foo().

http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

[toc] | [next] | [standalone]


#55928

From"christian.posta" <christian.posta@gmail.com>
Date2011-02-11 08:57 -0800
Message-ID<6da4b2d7-3b67-4f31-b73f-97df13215bee@k15g2000prk.googlegroups.com>
In reply to#55815
On Feb 11, 9:10 am, Robert Kern <robert.k...@gmail.com> wrote:
> On 2/11/11 9:06 AM, christian.posta wrote:
>
>
>
> > I searched quickly to see whether this may have been discussed before,
> > but it's possible my search criteria was not refined enough to get any
> > hits. Forgive me if this is a silly question..
>
> > I was reading some Python code from a third-party app for the django
> > project... i saw this in the code and I wasn't certain what it means,
> > nor could I find anything helpful from google.
>
> > Within the __call__ function for a class, I saw a method of that class
> > referred to like this:
>
> > *self.<method_name_here>()
>
> > The brackets indicate the method name.
> > What does the *self refer to??
> > Does it somehow indicate the scope of the 'self' variable?
>
> Can you show the whole statement? Most likely, this was embedded in some other
> call, e.g.:
>
>    foo(*self.method())
>
> If this is the case, the * does not bind to "self"; it binds to all of
> (self.method()), i.e.:
>
>    foo(*(self.method()))
>
> This is just the foo(*args) syntax that unpacks a tuple into individual
> arguments to pass to foo().
>
> http://docs.python.org/tutorial/controlflow.html#unpacking-argument-l...
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it had
>   an underlying truth."
>    -- Umberto Eco

Yep, you are correct!
It is indeed part of a larger statement. Sorry for the confusion.

Here is the entire snippet:

    def get_urls(self):
        # In Django 1.1 and later you can hook this in to your urlconf
        from django.conf.urls.defaults import patterns
        return patterns('', *self.get_urlpatterns())

[toc] | [prev] | [next] | [standalone]


#55997

From"christian.posta" <christian.posta@gmail.com>
Date2011-02-11 08:59 -0800
Message-ID<f6af0657-122d-4205-8a6c-42896f14c5f1@8g2000prb.googlegroups.com>
In reply to#55928
On Feb 11, 9:57 am, "christian.posta" <christian.po...@gmail.com>
wrote:
> On Feb 11, 9:10 am, Robert Kern <robert.k...@gmail.com> wrote:
>
>
>
> > On 2/11/11 9:06 AM, christian.posta wrote:
>
> > > I searched quickly to see whether this may have been discussed before,
> > > but it's possible my search criteria was not refined enough to get any
> > > hits. Forgive me if this is a silly question..
>
> > > I was reading some Python code from a third-party app for the django
> > > project... i saw this in the code and I wasn't certain what it means,
> > > nor could I find anything helpful from google.
>
> > > Within the __call__ function for a class, I saw a method of that class
> > > referred to like this:
>
> > > *self.<method_name_here>()
>
> > > The brackets indicate the method name.
> > > What does the *self refer to??
> > > Does it somehow indicate the scope of the 'self' variable?
>
> > Can you show the whole statement? Most likely, this was embedded in some other
> > call, e.g.:
>
> >    foo(*self.method())
>
> > If this is the case, the * does not bind to "self"; it binds to all of
> > (self.method()), i.e.:
>
> >    foo(*(self.method()))
>
> > This is just the foo(*args) syntax that unpacks a tuple into individual
> > arguments to pass to foo().
>
> >http://docs.python.org/tutorial/controlflow.html#unpacking-argument-l...
>
> > --
> > Robert Kern
>
> > "I have come to believe that the whole world is an enigma, a harmless enigma
> >   that is made terrible by our own mad attempt to interpret it as though it had
> >   an underlying truth."
> >    -- Umberto Eco
>
> Yep, you are correct!
> It is indeed part of a larger statement. Sorry for the confusion.
>
> Here is the entire snippet:
>
>     def get_urls(self):
>         # In Django 1.1 and later you can hook this in to your urlconf
>         from django.conf.urls.defaults import patterns
>         return patterns('', *self.get_urlpatterns())

Thank you both Ian and Robert. It now makes perfect sense!

Thanks!!

[toc] | [prev] | [next] | [standalone]


#56045

From"christian.posta" <christian.posta@gmail.com>
Date2011-02-11 08:59 -0800
Message-ID<c44f1678-f2ca-4328-9d4c-2a7578a8dd4d@o21g2000prn.googlegroups.com>
In reply to#55815
On Feb 11, 9:10 am, Robert Kern <robert.k...@gmail.com> wrote:
> On 2/11/11 9:06 AM, christian.posta wrote:
>
>
>
> > I searched quickly to see whether this may have been discussed before,
> > but it's possible my search criteria was not refined enough to get any
> > hits. Forgive me if this is a silly question..
>
> > I was reading some Python code from a third-party app for the django
> > project... i saw this in the code and I wasn't certain what it means,
> > nor could I find anything helpful from google.
>
> > Within the __call__ function for a class, I saw a method of that class
> > referred to like this:
>
> > *self.<method_name_here>()
>
> > The brackets indicate the method name.
> > What does the *self refer to??
> > Does it somehow indicate the scope of the 'self' variable?
>
> Can you show the whole statement? Most likely, this was embedded in some other
> call, e.g.:
>
>    foo(*self.method())
>
> If this is the case, the * does not bind to "self"; it binds to all of
> (self.method()), i.e.:
>
>    foo(*(self.method()))
>
> This is just the foo(*args) syntax that unpacks a tuple into individual
> arguments to pass to foo().
>
> http://docs.python.org/tutorial/controlflow.html#unpacking-argument-l...
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it had
>   an underlying truth."
>    -- Umberto Eco

Yep, you are correct!
It is indeed part of a larger statement. Sorry for the confusion.

Here is the entire snippet:

    def get_urls(self):
        # In Django 1.1 and later you can hook this in to your urlconf
        from django.conf.urls.defaults import patterns
        return patterns('', *self.get_urlpatterns())

[toc] | [prev] | [next] | [standalone]


#56144

From"christian.posta" <christian.posta@gmail.com>
Date2011-02-11 08:57 -0800
Message-ID<269b5697-7e72-4ecc-9265-58a156baedf7@y31g2000prd.googlegroups.com>
In reply to#55815
On Feb 11, 9:10 am, Robert Kern <robert.k...@gmail.com> wrote:
> On 2/11/11 9:06 AM, christian.posta wrote:
>
>
>
> > I searched quickly to see whether this may have been discussed before,
> > but it's possible my search criteria was not refined enough to get any
> > hits. Forgive me if this is a silly question..
>
> > I was reading some Python code from a third-party app for the django
> > project... i saw this in the code and I wasn't certain what it means,
> > nor could I find anything helpful from google.
>
> > Within the __call__ function for a class, I saw a method of that class
> > referred to like this:
>
> > *self.<method_name_here>()
>
> > The brackets indicate the method name.
> > What does the *self refer to??
> > Does it somehow indicate the scope of the 'self' variable?
>
> Can you show the whole statement? Most likely, this was embedded in some other
> call, e.g.:
>
>    foo(*self.method())
>
> If this is the case, the * does not bind to "self"; it binds to all of
> (self.method()), i.e.:
>
>    foo(*(self.method()))
>
> This is just the foo(*args) syntax that unpacks a tuple into individual
> arguments to pass to foo().
>
> http://docs.python.org/tutorial/controlflow.html#unpacking-argument-l...
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it had
>   an underlying truth."
>    -- Umberto Eco

Yep, you are correct!
It is indeed part of a larger statement. Sorry for the confusion.

Here is the entire snippet:

    def get_urls(self):
        # In Django 1.1 and later you can hook this in to your urlconf
        from django.conf.urls.defaults import patterns
        return patterns('', *self.get_urlpatterns())

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web