+3 votes
in Programming Languages by (73.8k points)

I need to pass some default values to a function and am calling the following function as follows:

X, Y, metavisits_list = fetch_data_from_npy_file(param='test', start_idx, end_idx)

I have defined the function, but I am getting syntax error "positional argument follows keyword argument". How can I fix it?

1 Answer

+1 vote
by (348k points)
selected by
Best answer

In your function, param is a keyword argument and start_idx/end_idx are positional arguments. Basically, a keyword argument is just a positional argument with a default value. If you understand the error message, you can fix it by putting positional arguments before keyword arguments. Make the following change and it will solve the problem.

X, Y, metavisits_list = fetch_data_from_npy_file(start_idx, end_idx, param='test')