博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python小工具
阅读量:6970 次
发布时间:2019-06-27

本文共 4009 字,大约阅读时间需要 13 分钟。

http://

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

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

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

python实现文件复制

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

from os import listdir, pathimport subprocessif __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 fnmatchfrom os import walk, path, removeimport sysif 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文件。

python代码出错重新启动

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

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

其他方法[]

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

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)

Python日常任务自己主动化

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

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

[]这本书正在翻译中

[]

开源:解决有意思问题的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

[]

使用python批量下载文件

[]

[]

[]

from:

ref:

转载地址:http://cnasl.baihongyu.com/

你可能感兴趣的文章
PHP获取今天、昨天、明天的日期
查看>>
[转载]DLL劫持生成器 源码开放(纯WINDOWS SDK)+ 实例分析
查看>>
在eclipse上Checkstyle的安装和使用
查看>>
控制流程完整性:给大家介绍一种“另类”的Javascript反分析技术
查看>>
vertica系列:数据的导入导出
查看>>
centos7如何添加开机启动服务/脚本
查看>>
Android OpenSL ES 开发:OpenSL ES利用SoundTouch实现PCM音频的变速和变调
查看>>
kafka学习指南(总结版)
查看>>
C#事件-使用事件需要的步骤
查看>>
[PWA] Cache JSON Data in a React PWA with Workbox, and Display it while Offline
查看>>
C++之List的用法,reference,参考,手册,man,帮助,
查看>>
yijing64
查看>>
The Stanford NLP (Natural Language Processing) Group
查看>>
ECSHOP-搜索引擎收录利器快速提升收录
查看>>
html页面实现指定位置的跳转
查看>>
c++学习笔记5
查看>>
【转】依赖抽象,不要依赖具体
查看>>
Creating a Swap Partition
查看>>
点击表格获取表格行或列索引
查看>>
不区分大小写
查看>>