Python和运维

来自linux中国网wiki
跳到导航 跳到搜索

python常用的运维脚本

py3 批量修改文件后缀名 或者去掉后缀名

#!/usr/bin/python3
# -*- coding:utf-8 -*-

#需要把程序放在与修改的文件同一目录下,因为filenames只是获取了程序目录的文件名。
# python批量更换后缀名
import os

# 列出当前目录下所有的文件
files = os.listdir('.')
for filename in files:
	portion = os.path.splitext(filename)
	# 如果后缀是.dat
	if portion[1] == ".txt":  
		# 重新组合文件名和后缀名 有两种情形在这个例子

                # txt 文件改为sh
                newname = portion[0] + ".sh"

                #去掉.txt后缀名
		newname = portion[0]  
		os.rename(filename,newname)


python文件操作3--批量修改文件后缀名


github.com 一些常用的Python脚本

Python运维常用的脚本,提高工作效率就靠它了

python常用的运维脚本有哪些

zhihu 你用 Python 写过哪些有趣的脚本?

python爬取廖雪峰教程存为PDF