Use of the Argparse module in Python

Source: Internet
Author: User

There are two files, one is

File 1:sync_shop_source_bimer.sh

File 2:sync_shop_source_bimer.py

Call sync_shop_source_bimer.py in sync_shop_source_bimer.sh

Files generated in file 1 are passed to file 2

What's in file 1

shop_flow_output= "/tmp/shop_flow_source"

shop_gmv_output= "/tmp/shop_gmv_source"

Yesday= ' date-d " -1day" + "%y-%m-%d" '

/usr/local/bin/python sync_shop_source_bimer.py--date $yesday--flow_file $shop _flow_output--deal_file $shop _gmv_ Output

Receive files in file 2

Import datetime

Import Argparse

Def Get_args ():
Parser = Argparse. Argumentparser ()
Parser.add_argument ('-d ', '--date ', help= ' date to stat, format:2015-03-01 ', default = Datetime.datetime.now (). strftime ("%y-%m-%d"))
Parser.add_argument ('-f ', '--flow_file ', help= ' flow file ')
Parser.add_argument ('-G ', '--deal_file ', help= ' GMV file ')

args = Parser.parse_args ()
return args

def main ():

args = Get_args ()

#打印接收参数

Print dt = Datetime.datetime.strptime (args.date, "%y-%m-%d")

Print Flow_shop = Args.flow_file

Print Gmv_shop = Args.deal_file

Use of the Argparse module in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.