Python- positional argument follows keyword argument

659    Asked by ranjan_6399 in Python , Asked on Jun 30, 2021

I have a function that 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 Python- positional argument follows keyword argument

.

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
Answered by Ranjana Admin

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

Note : This error is a syntax error which means that we have failed to follow one of the rules that governs how to write a Python code

To

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


Your Answer

Interviews

Parent Categories