Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 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
...