文件读写在Python程序或者工具中经常使用。#!/usr/bin/python import os def sha1Reader(sha1ListPath): sha1List = None try: sha1Reader = open(sha1ListPath, "r") sha1List = sha1Reader.r
FTP在各种应用中经常出现,Python也提供了相应的库:ftplib。#!/usr/bin/python import sys,os import ftplib class ftpClient: def __init__(self, logger): self.logger = logger self.ftp = None def
发送邮件的功能时常用到,在Python也是如此,当然可以使用Python调用jar发送邮件,但其实Python也有相应的模块:smtplib和email。#!/usr/bin/python # -*- coding: utf-8 -*- import smtplib from email.MIMEMultipart import MIMEMultipart from email.M
Python中关于Timeout有另一种用起来更简便的方法,即使用装饰器。这种方式是使用sys模块的settrace等方法重构了python的threading类:#!/usr/bin/python import threading import sys class KThread(threading.Thread): """Subclass of threading.Thread, w
Python中并没有Timeout模块,但是在程序中经常遇到需要超时控制的情况。 有两种思路去实现这种Timeout,其一是将需要做超时处理的代码块作为一个独立的子进程来处理,可将其另做一个包含main函数的.py文件。然后使用子进程超时限制来控制代码块运行的时间。#!/usr/bin/python import signal import s
Python 中的Log模块的使用 (1)首先定义公共的log获取方法:#!/usr/bin/python import logging.handlers LEVELS={'debug':logging.DEBUG, 'info':logging.INFO, 'warning':logging.WARNING, 'error':logging.ERROR, 'critic
Copyright © 2005-2025 51CTO.COM 版权所有 京ICP证060544号