zoukankan      html  css  js  c++  java
  • python中argparse模块的使用

    有两个文件一个是

    文件1:sync_shop_source_bimer.sh

    文件2:sync_shop_source_bimer.py

    在sync_shop_source_bimer.sh 中调用sync_shop_source_bimer.py

    文件1中产生的文件要传递给文件2

    文件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

    文件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文件')
      parser.add_argument('-g', '--deal_file', help='gmv文件')

      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

  • 相关阅读:
    数据仓库的一些理解(转)
    常见ETL工具一览,你知多少?
    dhcpv6开源软件配置
    svn
    js原型模式
    combo扩展:禁止手工改变输入框的值
    SQLite错误总结 error code 19: constraint failed
    ntp源码解读(一)
    ntp-keygen.c
    6.2.2认证
  • 原文地址:https://www.cnblogs.com/gide/p/5549186.html
Copyright © 2011-2022 走看看