禁用ConfigParser配置选项转化小写

Posted by 4Aiur on 04/20/2010 in Python |

禁用ConfigParser配置选项转化小写 ConfigParser在读取配置文件后默认会把配置项目转换为小写,调用下面的方法可以关闭转换功能。 cfgparser.optionxform = str

Tags:

python2.5.4 httplib timeout patch

Posted by 4Aiur on 04/06/2010 in Python |

python2.5.4 httplib timeout patch 632c632 def __init__(self, host, port=None, strict=None): 643,644d642

Tags: ,

使用python发送带附件的邮件

Posted by 4Aiur on 04/06/2010 in Python |

使用python发送带附件的邮件 #!/usr/bin/env python # -*- coding: utf-8 -*- from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase from email import utils, encoders import mimetypes, sys import smtplib import re import datetime def attachment(filename): fd = open(filename, “rb”) mimetype, mimeencoding = mimetypes.guess_type(filename) if mimeencoding or (mimetype is None): mimetype = “application/octet-stream” maintype, subtype […]

Tags: ,

使用Python解析Excel

Posted by 4Aiur on 04/06/2010 in Python |

使用Python解析Excel 解析Excel文件常用的module有pyExcelerator与xlrd,目前这两个模块只能支持excel2004以下版本生成的文件。 我写了一个从excel文件读取工资,并给员工发送工资条邮件的程序放在了github上,里面有一些解析excel文件细节的代码,有兴趣的同学可以下回去看看。 代码存放地址: https://github.com/mlf4aiur/payslip pyExcelerator范例 查看pyExcelerator的tools中xls2txt.py了解到pyExcelerator使用parse_xls方法解析excel文件。 调用parse_xls方法后,生成的结果为list,list的结构示例如下: [(u’Sheet1′, {(0, 0): 111, (0, 1): 112, (1, 0): 121, (1, 1): 122}), (u’Sheet2′, {(0, 0): 211, (0, 1): 212, (1, 0): 221, (1, 1): 222}), (u’Sheet3′, {})] 安装pyExcelerator sudo pip install pyExcelerator localhost:Share 4aiur$ ipython Leopard libedit detected. Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51) Type […]

Tags: ,

使用python计算md5

Posted by 4Aiur on 04/06/2010 in Python |

使用python计算md5 #!/usr/bin/env python3 import os import hashlib # Use hashlib module file = open(“foo”, “rb”) content = file.read() file.close() result = hashlib.md5() result.update(content) md5sum = result.hexdigest() print(md5sum) # Use OS command result = os.popen(“md5sum foo”).readline() md5sum = result.split()[0] print(md5sum)

Tags:

Copyright © 2010-2024 4Aiur All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.