Yashwanth Nataraj
Yashwanth Nataraj

Reputation: 193

is it possible to pass argument to a function in this way?

I am trying to pass argument to a function in this fashion

GroupGeneralConfig(selectedGroup = "Group1")

and the function looks like this...

def GroupGeneralConfig(self, *args)
     img = str(args[0]) + "abc"

whenever i execute this program it is throwing like this...

TypeError: GroupGeneralConfig() got an unexpected keyword argument 'selectedGroup'

whats wrong here

Upvotes: 0

Views: 101

Answers (3)

Amyth
Amyth

Reputation: 32949

What you are passing in is a keyword argument, change your method to accept keyword arguments first. Like this

def GroupGeneralConfig(self, *args, **kwargs)
     img = str(args[0]) + "abc"

Then you can pass the arguments first and then the keyword arguments, like:

GroupGeneralConfig(arg_x, arg_y, kwarg_x=1, kwarg_y=2)

Upvotes: 1

miku
miku

Reputation: 188004

You'll want the double star:

def GroupGeneralConfig(self, **kwargs):
    img = str(kwargs[selectedStreamGroup]) + "abc"

Upvotes: 2

filmor
filmor

Reputation: 32182

If you want to use kwargs you should define it first:

def GroupGeneralConfig(self, **kwargs):

Upvotes: 1

Related Questions