http://blog.csdn.net/pipisorry/article/details/46754515

python复制、删除文件代码、python代码出错重新启动

python遍历和删除指定文件夹下全部的pyc文件

网页抓取、阅读PDF/Word文档、与Excel电子表格交互、解析CSV/JSON文件、调度任务、发送邮件和SMS文本、基于Pillow模块的图像处理、通过GUI自己主动化控制键盘和鼠标

python实现文件复制

利用windows copy命令实现将一个文件夹中的文件拷贝到还有一个文件夹

from os import listdir, path
import subprocess if __name__ == "__main__":
INPUT_DIR = r'E:\Entertain\Videos'
OUTPUT_DIR = r'C:\Users\pi\Desktop\out'
all_output_dir_filenames = listdir(OUTPUT_DIR)
all_output_dir_filenames.append('desktop.ini') for file_name in listdir(INPUT_DIR):
if file_name not in all_output_dir_filenames:
filename = path.join(INPUT_DIR, file_name)
# print(filename)
subprocess.Popen(["copy", filename, OUTPUT_DIR], shell=True)

python遍历和删除指定文件夹下全部的pyc文件

E:\mine\python_workspace\Utility\DelPyc.py:





#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 'pi'
__mtime__ = '7/29/2015-029'
"""
import fnmatch
from os import walk, path, remove
import sys if len(sys.argv) >= 3:
EXT = sys.argv[2]
DEL_DIR = sys.argv[1]
elif len(sys.argv) >= 2:
EXT = 'pyc'
DEL_DIR = sys.argv[1]
else:
EXT = 'pyc'
DEL_DIR = r'E:\mine\python_workspace\WebSite'
if not path.exists(DEL_DIR):
print('error: DEL_DIR not found!!!')
exit()
print('DEL_DIR: ', DEL_DIR, '\ndelete file extension: ', EXT) print('deleted files:\n') def del_pyc(DEL_DIR):
for filepath, _, filename_list in walk(DEL_DIR):
for filename in filename_list:
if fnmatch.fnmatch(filename, '*.' + EXT): # unix shell风格匹配方式
# if filename.endswith('.pyc'):
print(filename)
remove(path.join(filepath, filename)) if __name__ == '__main__':
del_pyc(DEL_DIR)

Note:上面的程序是针对当前pycharm中打开的py文件相应的文件夹删除当中全部的pyc文件。假设是直接执行(而不是在以下的tools中执行)。则删除E:\mine\python_workspace\WebSite文件夹下的pyc文件。

皮皮blog

python代码出错重新启动

执行python代码某个片断出错。能够重新启动本代码继续执行

try:
...
except:
time.sleep(2)
subprocess.call(['python', sys.argv[0]])

其他方法[python实现自己主动重新启动本程序的方法]

计算身份证最后一位校验码

def identifier():
'''
计算身份证最后一位校验码
'''
id_card_str = '42028118921027721'
x = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
coefficient = np.array([7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]) id_card = np.array(list(id_card_str), dtype=int)
x_id = id_card.dot(coefficient) % 11
id_card_str += str(x[x_id])
print(id_card_str)

皮皮blog

Python日常任务自己主动化

日常繁琐任务(Python)自己主动化指南

内容包含网页抓取、阅读PDF/Word文档、与Excel电子表格交互、解析CSV/JSON文件、调度任务、发送邮件和SMS文本、基于Pillow模块的图像处理、通过GUI自己主动化控制键盘和鼠标等

[书:Automate the Boring Stuff with Python]这本书正在翻译中

[(Udemy):日常繁琐任务(Python)自己主动化指南免费课程]

开源:解决有意思问题的Python脚本集合

A collection of python scripts that solve interesting problems.
async_sched.py - A asynchronous scheduler implemented using coroutines, in principle similar to Tornado's ioloop
config_parser.py - My implementation of python standard library's ConfigParser module
dancing_links.py - My implementation of Dr. Knuth's dancing links algorithm, with a demo to solve N-Queen problem
disjoint_set.py - Disjoint set is a very important data structure, this is my naive implementation
fileinput.py - My implementation of python standard library's fileinput module
go_repl.py - A REPL for golang, support executing Go statements with instant feedback
html_template.py - A simple html template engine, supporting similar syntax as Django template language
lisp.py - A Lisp parser implemented in python, inspired by Peter Novig's essay
memento.py - Very elegant memento design pattern impl, copied from activestate recipes
patch_module.py - Patch python modules lazily, only when they are imported
quine.py - A python script to print itself
rpc.py - Simplistic RPC for python
timeit.py - My partial implementation of standard library's timeit module
emojify - Render an image with emoji's based on the colors in original image
web_terminal - A remote console from a web browser
online_judge - A OJ system like leetcode, with a small problemset, supporting only python solutions
image_crawler - A web image crawler written based on Tornado
http_server - A basic http server supporting static files/wsgi apps/proxying

[Beautifully constructed python scripts]

使用python批量下载文件

[Python下载文件的方法]

[用Python的requests模块下载文件]

[Python实现批量下载文件]

from:http://blog.csdn.net/pipisorry/article/details/46754515

ref:python系统模块sys、os和路径、系统命令

python文件夹遍历和删除指定文件夹下的pyc文件

如何遍历移除项目中的全部 .pyc 文件

python小工具的更多相关文章

  1. Python小工具--删除svn文件

    有的时候我们需要删除项目下的svn相关文件,但是SVN会在所有的目录下都创建隐藏文件.svn,手工一个个目录查找然后删除显然比较麻烦.所以这里提供了一个Python小工具用于批量删除svn的相关文件: ...

  2. python小工具myqr生成动态二维码

    python小工具myqr生成动态二维码 (一)安装 (二)使用 (一)安装 命令: pip install myqr 安装完成后,就可以在命令行中输入 myqr 查看下使用帮助: myqr --he ...

  3. 一个Json结构对比的Python小工具兼谈编程求解问题

    先上代码. jsondiff.py #!/usr/bin/python #_*_encoding:utf-8_*_ import argparse import json import sys rel ...

  4. python小工具:用python操作HP的Quality Center (二)----- 用异步方式提高速度

    上接第一篇 http://www.cnblogs.com/sdet/p/6874631.html 在python中,很简单地能把http请求通过异步的方式发送,以下代码在python 3.6.0上运行 ...

  5. 自制 Python小工具 将markdown文件转换成Html文件

    今天看到了一个Python库,名为markdown.瞬间就给了我一个灵感,那就是制作一个将markdown文件转换成html文件的小工具. 我的实验环境 操作系统: Windows 7 64位 旗舰版 ...

  6. 有哪些你不知道的python小工具

    python作为越来越流行的一种编程语言,不仅仅是因为它语言简单,有许多现成的包可以直接调用. python中还有大量的小工具,让你的python工作更有效率. 1.- 快速共享 - HTTP服务器 ...

  7. 分享一个 Linux 环境下,强力的Python 小工具

    场景 Linux 用户,经常需要在终端查看一些数据,从文件里看 或者网络协议获取数据并查看. 比如,查看文件里的json数据:比如,查看etcd里存下的数据. 如果直接看cat 或者 curl 得到的 ...

  8. Python小工具:利用ffmpy3库3秒钟将视频转换为音频

    作者 | pk 哥 来源公众号 | Python知识圈(ID:PythonCircle) 最近,有读者微信上私聊我,想让我写一篇视频批量转换成音频的文章,我答应了,周末宅家里把这个小工具做出来了. 这 ...

  9. 周报?谁还写周报啊?不都用Python小工具: 发个周报邮件给老板就行还写周报啊?不都用Python小工具: 发个周报邮件给老板就行

    缘起: 新跳槽到一家公司, 没想到第一个挑战居然是每周都要发周报. 告诉老板这周都干了些什么和下周准备干什么. 我记性不好, 常常忘事儿.所以很多时候周报都会忘记发送. 于是, 就决定写一个小工具好了 ...

  10. python小工具:用python操作HP的Quality Center

    背景是这样的:这个组的测试人员每跑一个case都要上传测试结果附件到QC.每个待测功能模块可能包含几十上百的case.于是手工上传测试结果变成了繁重的体力劳动.令人惊讶的是我们的工具开发组竟然说做不了 ...

随机推荐

  1. uva 10537 Toll! Revisited(优先队列优化dijstra及变形)

    Toll! Revisited 大致题意:有两种节点,一种是大写字母,一种是小写字母. 首先输入m条边.当经过小写字母时须要付一单位的过路费.当经过大写字母时,要付当前財务的1/20做过路费. 问在起 ...

  2. CSS控制当鼠标滑过时更换图片的效果

    鼠标滑过时更换图片的效果有很多方法可以实现,在本文将为大家介绍喜爱如何通过css来实现.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tra ...

  3. 腾讯云数据库团队:MySQL5.7 JSON实现简单介绍

    作者介绍:吴双桥 腾讯云project师 阅读原文.很多其它技术干货.请訪问fromSource=gwzcw.57435.57435.57435">腾云阁. 本文主要介绍在MySQL ...

  4. ios笔记一 追加数据

    //追加数据 NSString *homePat = NSHomeDirectory(); NSString *sourcePath = [homePath stringByAppedingPathC ...

  5. nyoj592 spiral grid

    spiral grid 时间限制:2000 ms  |  内存限制:65535 KB 难度:4   描述 Xiaod has recently discovered the grid named &q ...

  6. iOS截屏功能

    代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // ...

  7. 针对Properties中实时性要求不高的配置参数,用Java缓存起来

    Properties常用于项目中参数的配置,当项目中某段程序需要获取动态参数时,就从Properties中读取该参数,使程序是可配置的.灵活的. 有些配置参数要求立即生效,有些则未必: 一.实时性要求 ...

  8. [小技巧]Mac上chrome打开触控板双指前进后退功能

    Orz,本以为是默认开启的,结果发现并不是,从系统里找了半天发现没找到-就搜了一下,原来可以命令开启来 defaults write com.google.Chrome AppleEnableSwip ...

  9. RSS Feeds with Spring Boot

    http://nixmash.com/post/rss-feeds-with-spring-boot **************************************** We added ...

  10. Oracle数据库字符集问题解析

    Oracle数据库字符集问题解析 经常看到一些朋友问ORACLE字符集方面的问题,我想以迭代的方式来介绍一下.第一次迭代:掌握字符集方面的基本概念.有些朋友可能会认为这是多此一举,但实际上正是由于对相 ...