cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform 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

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group