Passing keywords

Discussion in 'Python' started by Kless, Jul 20, 2008.

  1. Kless

    Kless Guest

    I've a constructor with several values that must be used by any
    functions:

    ---------------
    class foo:

    def __init__(self, foo1, foo2, foon):

    self.__check(foo1=foo1, foo2=foo2, foon=foon)
    self.__check2(foo1=foo1, foo2=foo2, foon=foon)

    def __check(self, foo1, foo2, foon):
    ...

    def __check2(self, foo1, foo2, foon):
    ...
    ---------------

    How simplify all that?

    I could use the next but I don't think...

    ---------------
    def __check(self, **keywords):
    ---------------
    Kless, Jul 20, 2008
    #1
    1. Advertising

  2. Kless wrote:

    > I could use the next but I don't think...
    >
    > ---------------
    > def __check(self, **keywords):
    > ---------------


    don't think what?

    if you keep using the same variables in all submethods you call from a
    method inside the class, why not make them attributes?

    otherwise, using the **-form when *calling* the methods might work. you
    can use the **-form in the functions to ignore arguments that you're not
    interested in.

    self.__check(**kwargs)
    self.__check2(**kwargs)

    def __check(self, foo1, foo2, **extra):
    # use foo1 and foo2 here; ignore the rest

    etc.

    </F>
    Fredrik Lundh, Jul 20, 2008
    #2
    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. Bruce
    Replies:
    0
    Views:
    687
    Bruce
    Aug 13, 2004
  2. valentin tihomirov

    Advantages of denying keywords as identifiers

    valentin tihomirov, Dec 17, 2004, in forum: VHDL
    Replies:
    8
    Views:
    511
    Mike Treseler
    Dec 28, 2004
  3. dw

    Friend & Protected keywords

    dw, May 15, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,852
  4. David Lozzi

    Search using multiple keywords

    David Lozzi, Jun 2, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    527
    David Lozzi
    Jun 2, 2005
  5. =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=

    Where to find HTML keywords ?

    =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=, Oct 11, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    391
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=
    Oct 11, 2005
Loading...

Share This Page