Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have a function which accepts the variable length of arguments as described below. I am passing the kwargs as a dictionary. However, I don't understand why I am getting the error.

class PanSearch(object): 

otp_wait = 30 

def __init__(self, surname, dob, mobile_no, otp_host, 

**kwargs): 

kwargs.setdefault('browser', 'chromium') 

self.surname = surname 

self.dob = dob 

self.mobile_no = mobile_no 

self.otp_host = otp_host 

self.middle_name = kwargs.get('middle_name', None) 

self.first_name = kwargs.get('first_name', None)

 self.status = kwargs.get('status') 

self.gender = 'M' if kwargs.get('status') == 'P' else 

None 

object otp_host = 'abc.xyz.in' 

input_kwargs = {'status': 'P', 'gender': 'M', 'browser': 'chromium'} 

driver = PanSearch(surname='kulkarni', dob='13/10/1981', mobile_no='9769172006', otp_host, **input_kwargs) 

File "pan_no.py", line 87 

  driver = PanSearch(surname='kulkarni', dob='13/10/1981', mobile_no='9769172006', otp_host, **input_kwargs) 

SyntaxError: positional argument follows keyword argument

1 Answer

0 votes
by (106k points)

If you want that your Python code should follow keyword argument then you need to change some lines with the below-mentioned code:-

driver = PanSearch(surname='kulkarni', dob='13/10/1981', mobile_no='9769172006', otp_host, **input_kwargs)

To

driver = PanSearch('kulkarni', '13/10/1981', '9769172006', otp_host, **input_kwargs)

Learn python with the help of this python training and also visit the python interview questions.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...