# batch_file_rename.py
# Created: 6th August 2012
# coding:utf-8
"""
This will batch rename a group of files in a given directory,
once you pass the current and new extensions
"""
# just checking
__author__ = 'Craig Richards'
__version__ = '1.0'
import os
import argparse
"""
python3中argparse模块
1、定义:argparse是python标准库里面用来处理命令行参数的库
2、命令行参数分为位置参数和选项参数:
位置参数就是程序根据该参数出现的位置来确定的
如:[root@openstack_1 /]# ls root/ #其中root/是位置参数
选项参数是应用程序已经提前定义好的参数,不是随意指定的
如:[root@openstack_1 /]# ls -l # -l 就是ls命令里的一个选项参数
3、使用步骤:
(1)import argparse 首先导入模块
(2)parser = argparse.ArgumentParser() 创建一个解析对象
(3)parser.add_argument() 向该对象中添加你要关注的命令行参数和选项
(4)parser.parse_args() 进行解析
4、argparse.ArgumentParser()方法参数须知:
Python:批处理文件后缀名 batch_file_rename.py(源程序+详细讲解)
最新推荐文章于 2023-06-19 13:15:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)