Passing keywords

K

Kless

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):
...
 
F

Fredrik Lundh

Kless said:
I could use the next but I don't think...

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top