解压文件夹中的压缩文件 Python脚本
下载了很多压缩文件,就写了一个脚本
在Python中使用winrar命令,所以一般压缩文件都支持
有些压缩文件Python中还没有相应的库
你得先把winrar添加到path环境变量中
把代码保存为rar.py
在dos下使用,如:rar.py "D:\A B\C" mkdir
#rar.py
#decompress with winrar
#arguments :filename directory opt
# opt='mkdir' to create directory with the correspond filename
# opt='direct' to decompress rar files in current directory
# opt='mk&del' to mkdir and delete rar file
import os
import sys
if len(sys.argv)!=3:
print ('wrong arguments\n')
print ('rar.py directory opt\n')
print ('opt=\'mkdir\' to create directory with the correspond filename\n')
print ('opt=\'direct\' to decompress rar files in current directory\n')
print ('opt=\'mk&del\' to mkdir and delete rar file\n')
exit(0)
#-ibck ,minimized when running
opt=sys.argv[2]
os.chdir(sys.argv[1])
for file in os.listdir('.'):
if os.path.isfile(file) and os.path.splitext(file)[1]=='.rar':
if opt=='mkdir':
cmd='winrar x -ibck "'+file+'"'+' "'+os.path.splitext(file)[0]+'"\\'
os.system(cmd)
elif opt=='direct':
cmd='winrar x -ibck "'+file+'"'
os.system(cmd)
elif opt=='mkdel':
cmd='winrar x -ibck "'+file+'"'+' "'+os.path.splitext(file)[0]+'"\\'
os.system(cmd)
os.remove(file)
else :
print('wrong option')
相关文档:
简单加密,用python来写写。
#coding=utf-8
'''
Description: 可逆的加密与解密
Environment: python2.5.x
Author:idehong@gmail.com
'''
import os
import sys
class Code(object):
'''可逆的加密与解密'''
def __init__(self, key = "idehong@gmail.com"):
self.__src_key ......
为了从字符串中提取时间,并进行比较,因此有了这个问题,如何将字符串转换成datetime类型
1.字符串与time类型的转换
>>> import time
>>> timestr = "time2009-12-14"
>>> t = time.strptime(timest ......
一颗语法糖——装饰器
理论不去管,只管能办事:
1. 我要让一个函数在执行的时候,去做一些事情,比如,我要看看这些函数是不是有docstring,将这个功能拿出来,定义一个装饰器:
def showmedoc(func):
if func.__doc__:
& ......
一、
为了使用python操作串口,首先需要下载相关模块:
1. pyserial (http://pyserial.wiki.sourceforge.net/pySerial)
2. pywin32 (http://sourceforge.net/projects/pywin32/)
二、
google “python 串口 操作”关键字,找到相关python代码,
我是从http://currentlife.blog.sohu.com/53741351.html页面上 ......
用Python导出QQ空间的日志到WordPress
文章来源:http://www.keakon.cn/bbs/thread-964-1-1.html方法很简单,找出日志的地址,再遍历列出日志的内容。
因为单纯导出没用,还得转换成其他格式,所以我保存到一个列表里,每篇日志都对应其中的一个字典元素,字典的属性都用unicode编码。
然后dump出来,可以方便以后用Pyth ......