python如何实现像shell中的case功能


import getopt
import sys arg = getopt.getopt(sys.argv[:],'-h',['help'])
print(arg)
root@Kali:~/python# python3. test.py -h
([('-h', '')], [])
root@Kali:~/python# python3. test.py --help
([('--help', '')], [])
#!/usr/bin/env python3.5
import urllib.request
import getopt
import sys opts,args = getopt.getopt(sys.argv[1:],'-h-f:-v',['help','filename=','version'])
for opt_name,opt_value in opts:
if opt_name in ('-h','--help'):
print("[*] Help info")
exit()
if opt_name in ('-v','--version'):
print("[*] Version is 0.01 ")
exit()
if opt_name in ('-f','--filename'):
fileName = opt_value
print("[*] Filename is ",fileName)
# do something
exit()
root@Kali:~/python# python3. test.py --filename=test
[*] Filename is test
root@Kali:~/python# python3. test.py --filename=
[*] Filename is
root@Kali:~/python# python3. test.py --help
[*] Help info
root@Kali:~/python# python3. test.py --version
[*] Version is 0.01
root@Kali:~/python# python3. test.py -v
[*] Version is 0.01
root@Kali:~/python# python3. test.py -f test
[*] Filename is test
root@Kali:~/python#
python如何实现像shell中的case功能的更多相关文章
- shell中的case表达式
语法格式 case var in pattern1 | patter2) command1 command2;; pattern3) command1 command2;; *) default co ...
- Python里如何实现C中switch...case的功能
python没有switch case 不过可以通过建立字典实现类似的功能 例子:根据输入的年月日,判断是该年中的第几天 y = int(input('请输入年:')) m = int(input(' ...
- Shell中的case命令
case语句和判断语句[if...elif...else]功能类似;当在逻辑判断比较简单的情况下,比后者的代码量要少许多.case用法,用变量来匹配某值,如果匹配成功则执行它下面的命令,直到 ::为止 ...
- shell中的case语句
case语法: case $arg in arg1) 语句1 ;; arg2) 语句2 ;; *) help 语句 ;; esac eg: eg:
- shell编程学习笔记(九):Shell中的case条件判断
除了可以使用if条件判断,还可以使用case 以下蓝色字体部分为Linux命令,红色字体的内容为输出的内容: # cd /opt/scripts # vim script08.sh 开始编写scrip ...
- python3-file的修改实现类似shell中sed的功能
# Auther: Aaron Fan '''思路:目的是为了修改yesterday这个文件,但是因为无法直接去修改这个文件,所以需要先把修改好的内容写入高yesterday.new这个文件中,然后再 ...
- Python 利用字典实现类似 java switch case 功能
def add(): print('add') def sub(): print('sub') def exit(): print('exit') choice = { '1' : add, '2' ...
- (二)shell中case语句、程序传参、while
2.2.6.1.case语句(1)shell中的case语句和C语言中的switch case语句作用一样,格式有差异(2)shell中的case语句天生没有break,也不需要break,和C语言中 ...
- shell中case的用法学习笔记
这篇文章主要为大家介绍shell中的case语句:可以把变量的内容与多个模板进行匹配,再根据成功匹配的模板去决定应该执行哪部分代码. 本文转自:http://www.jbxue.com/article ...
随机推荐
- Linux环境变量具体内容介绍
在Linux中,环境变量是一个很重要的概念.环境变量可以由系统.用户.Shell以及其他程序来设定. 变量就是一个可以被赋值的字符串,赋值范围包括数字.文本.文件名.设备以及其他类型的数据. 下面的例 ...
- 【Spark-core学习之四】 Spark任务提交
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk1.8 scala-2.10.4(依赖jdk1.8) spark ...
- MB SD Connect Compact 5 Error 95.53392.0 Solved
MB SD Connect Compact 5 is new released from MB Star company ,and its original version here the copy ...
- php 排列组合函数(无重复组合,可重复组合【全排列组合】)
<?php /** * 无重复排列組合 * @Author MAX * @DateTime 2018-09-07T16:28:40+0800 * @param Array $arr 需要排列組合 ...
- Git命令git update-index --assume-unchanged,忽略不想提交的文件(忽略跟踪)
场景 我们在自己的私有测试分支上调试项目逻辑,给文件做了一些特定的修改,但是文件不想被git提交,不想执行git status命令时出现在modified列表里:再比如,我们本地的数据库和测试环境的数 ...
- Docker Kubernetes Service 代理服务创建
Docker Kubernetes Service 代理服务创建 创建Service需要提前创建好pod容器.再创建Service时需要指定Pod标签,它会提供一个暴露端口默会分配容器内网访问的唯一 ...
- Linux 查看磁盘使用情况
Linux 查看磁盘使用情况 df 查看当前挂载空间使用情况 语法: df [选项]... [FILE]... 文件-a, --all 包含所有的具有 0 Blocks 的文件系统 文件--block ...
- win7下Oracle库impdp导入dmp
第一步:创建备份文件存储目录 create or replace directory back_file as 'D:\app\yangxf\back_or_memery_file'; create ...
- server time zone
问题原因 由于使用的Mysql数据库驱动版本太高,存在数据库和系统时区差异,所以出问题. 问题解决 Spring Boot配置文件中在url: jdbc:mysql://127.0.0.1:3306/ ...
- Macro-Micro Adversarial Network for Human Parsing
Macro-Micro Adversarial Network for Human Parsing ECCV-2018 2018-10-27 15:15:07 Paper: https://arxiv ...