Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,771 questions

10,854 answers

573 users

How to create a class with method and dynamic parameters in Python

4 Answers

0 votes
class Test:

    def __init__(self):
        print("Class Test instance initialized")

    def __call__(self, *arguments, **keywords):
        print("Arguments are:", arguments, keywords)

o = Test()
print("call the instance:")
o(7, 8, 9, 10, a=11, b=22, c=33)


'''
run:

Class Test instance initialized
call the instance:
Arguments are: (7, 8, 9, 10) {'a': 11, 'c': 33, 'b': 22}

'''

 




answered Dec 19, 2017 by avibootz
0 votes
class Test:

    def __init__(self):
        print("Class Test instance initialized")

    def __call__(self, *arguments, **keywords):
        for i in arguments:
            print(i)

o = Test()
print("call the instance:")
o(7, 8, 9, 10, a=11, b=22, c=33)


'''
run:

Class Test instance initialized
call the instance:
7
8
9
10

'''

 




answered Dec 19, 2017 by avibootz
0 votes
class Test:

    def __init__(self):
        print("Class Test instance initialized")

    def __call__(self, *arguments, **keywords):
        for i in keywords:
            print(keywords[i])

o = Test()
print("call the instance:")
o(7, 8, 9, 10, a=11, b=22, c=33)


'''
run:

Class Test instance initialized
call the instance:
33
22
11

'''

 




answered Dec 19, 2017 by avibootz
0 votes
class Test:

    def __init__(self):
        print("Class Test instance initialized")

    def __call__(self, *arguments, **keywords):
        print("Arguments are:", arguments, keywords)

o = Test()
print("call the instance:")
o(7, 8, 9, 10, a=11, b=22, c=33)
o(300, 400, a=8888, b=7777, c=6666, d=5555)


'''
run:

Class Test instance initialized
call the instance:
Arguments are: (7, 8, 9, 10) {'c': 33, 'b': 22, 'a': 11}
Arguments are: (300, 400) {'d': 5555, 'c': 6666, 'b': 7777, 'a': 8888}

'''

 




answered Dec 19, 2017 by avibootz
...