cancel
Showing results for 
Search instead for 
Did you mean: 
Community Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Arguments parsing in Databricks python jobs

Klusener
New Contributor

On Databricks created a job task with task type as Python script from s3. However, when arguments are passed via Parameters option, running into unrecognized arguments' error.

Code in s3 file:

import argparse

def parse_arguments():
    parser = argparse.ArgumentParser(description='Parse and print command line arguments')
    parser.add_argument('--first_argument', action='store_true', help='first argument')
    parser.add_argument('--second_argument', action='store_true', help='second argument')

    args = parser.parse_args()

    return args

def main():
    args = parse_arguments()

    print('--first_argument', args.first_argument)
    print('--second_argument', args.second_argument)

if __name__ == "__main__":
    main()

Approach-1: parameters passed

["--first_argument","val1","--second_argument","val2"]

Error: tmpm3.py: error: unrecognized arguments: val1 val2

Approach-2: parameters passed

["--first_argument val1","--second_argument val2"]

Error: tmpshby3l: error: unrecognized arguments: --first_argument val1 --second_argument val2

0 REPLIES 0
Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!