为python脚本增加命令行参数
from argparse import ArgumentParser
p = ArgumentParser()
p.add_argument('-b', '--body', help='Return USN records in comma-separated format', action='store_true')
p.add_argument('-c', '--csv', help='Return USN records in comma-separated format', action='store_true')
p.add_argument('-f', '--file', help='Parse the given USN journal file', required=True)
p.add_argument('-o', '--outfile', help='Parse the given USN journal file', required=True)
p.add_argument('-s', '--system', help='System name (use with -t)')
p.add_argument('-t', '--tln', help='TLN ou2tput (use with -s)', action='store_true')
p.add_argument('-v', '--verbose', help='Return all USN properties for each record (JSON)', action='store_true')
args = p.parse_args()
journalSize = os.path.getsize(args.file)
with open(args.file, 'rb') as i:
with open(args.outfile, 'wb') as o:
i.seek(findFirstRecord(i))
if args.csv:
do something
使用标准库的参数分析模块, 以属性的方式, 拿到具体的参数.
为python脚本增加命令行参数的更多相关文章
- 如何让python脚本支持命令行参数--getopt和click模块
一.如何让python脚本支持命令行参数 1.使用click模块 如何使用这个模块,在我前面的博客已经写过了,可参考:https://www.cnblogs.com/Zzbj/p/11309130.h ...
- powershell脚本,命令行参数传值,并绑定变量的例子
这是小技巧文章,所以文章不长.但原创唯一,非常重要.我搜了下,还真没有人发 powershell怎样 [命令行 参数 绑定],所以我决定写成博客. 搜索关键字如下: powershell 命令行 参数 ...
- 【前端】Vue和Vux开发WebApp日志四、增加命令行参数
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/vue_vux_4.html 项目github地址:https://github.com/shamoyuu/vue- ...
- Python 处理脚本的命令行参数(二):使用click
安装click pip install click 使用步骤 使用@click.command() 装饰一个函数,使之成为命令行接口 使用@click.option() 等装饰函数,为其添加命令行选项 ...
- Python 处理脚本的命令行参数-getopt
# -*- coding:utf-8 -*- import sys def test(): """ 参数列表:sys.argv 参数个数:len(sys.argv) 脚本 ...
- appium+python自动化59-appium命令行参数
Appium服务器参数 许多Appium 1.5服务器参数已被弃用,以支持--default-capabilities标志. 用法: node . [flags] help 1.cmd端口输入,app ...
- python中处理命令行参数的模块optpars
optpars是python中用来处理命令行参数的模块,可以自动生成程序的帮助信息,功能强大,易于使用,可以方便的生成标准的,符合Unix/Posix 规范的命令行说明.使用 add_option() ...
- python argparse:命令行参数解析详解
简介 本文介绍的是argparse模块的基本使用方法,尤其详细介绍add_argument内建方法各个参数的使用及其效果. 本文翻译自argparse的官方说明,并加上一些笔者的理解 import a ...
- Python 处理脚本的命令行参数(三):使用argparse
# coding:utf-8 # 测试argparse模块的基本用法 import argparse # 创建参数解析对象,并添加脚本用法帮助 parser = argparse.ArgumentPa ...
随机推荐
- flask 基础2
一.装饰器的坑 在使用装饰器函数时候,当一个装饰器装饰多个函数的时候,会由于内存地址相同时发生报错,因为装饰的都是一个函数 所以就需要引入 import functools 重新定义每一个函数的名称 ...
- fd (int)读写文件
#include <string.h> #include <stdio.h> #include <fcntl.h> int main() { char *p1 = ...
- Linux sh、source和.命令执行.sh文件的区别
sh文件介绍 .sh为Linux的脚本文件,我们可以通过.sh执行一些命令,可以理解为windows的.bat批处理文件. 点命令 .命令和source是同一个命令,可以理解为source的缩写,简称 ...
- Urllib 库使用
什么是Urllib Urllib是python内置的HTTP请求库包括以下模块urllib.request 请求模块 -->用来模拟发送请求 类似于输入网址敲击回车的过程urllib.er ...
- zz1998_Efficient Backprop笔记
1998_Efficient Backprop笔记 A few practical tricks 1. Stochastic vs Batch learning 在最小值附近震荡的幅度与学习速率成比例 ...
- Python进阶-V 迭代器(Iterator)、生成器(Generator)函数
一.迭代器 1.可循环的有哪些,即可用for语句或者while语句的数据类型有哪些? 字符串(str).列表(list).元组(tuple).字典(dic).集合(set).枚举类(enumerate ...
- <Random>382 380
382. Linked List Random Node class Solution { ListNode node; Random random; /** @param head The link ...
- 使用jQuery的replaceWith()方法要注意的地方
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 前端Vue项目——课程详情页面实现
一.详情页面路由跳转 应用 Vue Router 编程式导航通过 this.$router.push() 来实现路由跳转. 1.绑定查看详情事件 修改 src/components/Course/Co ...
- LoadRunner名词解释
Transactions(用户事务分析):用户事务分析是站在用户角度进行的基础性能分析. 1.Transation Sunmmary(事务综述) 对事务进行综合分析是性能分析的第一步,通过分析测试时间 ...