cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

Arguments parsing in Databricks python jobs

Klusener
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 Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now