- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 01:12 AM
Hi,
I have a method named main it takes **kwargs as a parameter.
def main(**kwargs):
parameterOne = kwargs["param-one"]
parameterTwo = kwargs["param-two"]
parameterThree = kwargs["param-optional-one"] if "param-optional-one" in kwargs else None
parameterFour = kwargs["param-optional-two"] if "param-optional-two" in kwargs else None
I have declared it as an entry_point in setup
entry_points={
'console_scripts': [
'main=ETL.V1:main'
]
},
I am passing keyword arguments in task
"entry_point": "main",
"named_parameters": {
"param-one": "test",
"param-two": "test two"
}
when I run the job it goes into main method, but fails on the very first line
KeyError: 'param-one'
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<command--1> in <module>
16 if entry:
17 # Load and execute the entrypoint, assumes no parameters
---> 18 entry[0].load()()
19 else:
20 import ETL.V1
/databricks/python/lib/python3.8/site-packages/ETL/V1.py in main(**kwargs)
8 for i, v in kwargs.items():
9 print(" ", i, ": ", v)
---> 10 parameterOne = kwargs['param-one']
11 parameterTwo = kwargs['param-two']
KeyError: 'param-one'
The keyword arguments are not being passed or I am doing something wrong?
I tried to see if anything is in kwargs, however that didn't print anything in the task output just the error above was displayed. So, I can't really tell if anything is in kwargs or not.
- Labels:
-
Entry Point
-
Method
-
Task Parameters
-
Wheel
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 03:41 AM
it is command-line parameters so it is like
---param-one=test
you can test it with ArgumentParser
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("--param-one", dest="parameterOne")
args = parser.parse_args()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 03:41 AM
it is command-line parameters so it is like
---param-one=test
you can test it with ArgumentParser
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("--param-one", dest="parameterOne")
args = parser.parse_args()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2022 05:54 AM
Hi,
Thanks for you answer.
Yes, what you say is correct, we must use argparse to get the keyword arguments.
Though, doing argparse outside of the entry point method didn't work for me.
I had to do it inside the method.
I have no idea why? I will try it again in an hour, for now I was happy to be able to get it working.
Thanks
I will select your answer.
I will comment back here if it can be down outside of the entry method.

