Re: Best place for a function?

Discussion in 'Python' started by Inyeol Lee, Mar 9, 2007.

  1. Inyeol Lee

    Inyeol Lee Guest

    On Wed, Mar 07, 2007 at 05:27:04PM -0500, Sergio Correia wrote:
    > I'm writing a class, where one of the methods is kinda complex. The
    > method uses a function which I know for certain will not be used
    > anywhere else. This function does not require anything from self, only
    > the args passed by the method.
    >
    > Where should I put the function?


    Use staticmethod. It's a normal function with class namespace.

    --Inyeol
    Inyeol Lee, Mar 9, 2007
    #1
    1. Advertising

  2. Inyeol Lee a écrit :
    > On Wed, Mar 07, 2007 at 05:27:04PM -0500, Sergio Correia wrote:
    >
    >>I'm writing a class, where one of the methods is kinda complex. The
    >>method uses a function which I know for certain will not be used
    >>anywhere else. This function does not require anything from self, only
    >>the args passed by the method.
    >>
    >>Where should I put the function?

    >
    >
    > Use staticmethod. It's a normal function with class namespace.


    What do you think the OP will gain from making a simple helper function
    a staticmethod ? Apart from extra lookup time ?
    Bruno Desthuilliers, Mar 11, 2007
    #2
    1. Advertising

  3. Inyeol Lee

    Inyeol Lee Guest

    On Sun, Mar 11, 2007 at 06:36:02PM +0100, Bruno Desthuilliers wrote:
    > Inyeol Lee a écrit :
    > > On Wed, Mar 07, 2007 at 05:27:04PM -0500, Sergio Correia wrote:
    > >
    > >>I'm writing a class, where one of the methods is kinda complex. The
    > >>method uses a function which I know for certain will not be used
    > >>anywhere else. This function does not require anything from self, only
    > >>the args passed by the method.
    > >>
    > >>Where should I put the function?

    > >
    > >
    > > Use staticmethod. It's a normal function with class namespace.

    >
    > What do you think the OP will gain from making a simple helper function
    > a staticmethod ? Apart from extra lookup time ?


    Namespace.
    Plz check this old thread. It explains some usage of staticmethod.
    http://mail.python.org/pipermail/python-list/2003-February/190258.html

    --Inyeol
    Inyeol Lee, Mar 13, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gandalf
    Replies:
    1
    Views:
    444
    Steve C. Orr, MCSD
    Jul 18, 2003
  2. Leo Muller
    Replies:
    4
    Views:
    3,765
    Josh Harris
    Feb 17, 2004
  3. Schoo
    Replies:
    5
    Views:
    3,851
    Steven Cheng[MSFT]
    Mar 3, 2004
  4. Arvind P Rangan

    Where is best place to put DB connection string?

    Arvind P Rangan, Mar 1, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    607
    Martin Dechev
    Mar 1, 2004
  5. Sergio Correia

    Best place for a function?

    Sergio Correia, Mar 7, 2007, in forum: Python
    Replies:
    4
    Views:
    261
    Sergio Correia
    Mar 7, 2007
Loading...

Share This Page