Passing keywords

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kless

    Passing keywords

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

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

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

    self.__check(fo o1=foo1, foo2=foo2, foon=foon)
    self.__check2(f oo1=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):
    ---------------
  • Fredrik Lundh

    #2
    Re: Passing keywords

    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>

    Comment

    Working...