解压文件夹中的压缩文件 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')
相关文档:
from random import randint #导入随即函数
def guessNum(): &nbs ......
Python 3 输出重定向使用C/C++
By:gddsky
目标
希望将Python 3的输出重定向到自定义的输出目标。
核心
Python使用sys.stdout、sys.stderr做输出目标,只要我们替换这两个值就可以重定向到我们自定义目标。替换的值的规则在Python的文档中sys (module)的sys.stdout上面说明只要添加一个write函数就可以 ......
1. Python 串口设备应用
简述
1.1. 线程轮寻
风尘无限 <tianyu263@163.com>
-- 分享
就是打开串口后,启动一个线程来监听串口数据的进入,有数据时,就做数据的处理(也可以发送一个事件,并携带接收到的数据)。
Toggle line numbers
1
2 #coding=gb18030
3
4 i ......
用Python导出QQ空间的日志到WordPress
文章来源:http://www.keakon.cn/bbs/thread-964-1-1.html方法很简单,找出日志的地址,再遍历列出日志的内容。
因为单纯导出没用,还得转换成其他格式,所以我保存到一个列表里,每篇日志都对应其中的一个字典元素,字典的属性都用unicode编码。
然后dump出来,可以方便以后用Pyth ......
综合网上查到的内容,写的Python发送邮件的类。附件部分还没写好,主要是附件的文件名部分还不对。
#!/usr/bin/env python
# coding:utf-8
import email
import smtplib
class Mailer:
def __init__(self, smtp_host, smtp_user, smtp_passwd, smtp_port = 25) :
self.smtp_host = smtp_host
s ......