Python·¢ËÍÓʼþµÄÀà
×ÛºÏÍøÉϲ鵽µÄÄÚÈÝ£¬Ð´µÄ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
self.smtp_user = smtp_user
self.smtp_passwd = smtp_passwd
self.smtp_port = smtp_port
self.mail = email.MIMEMultipart.MIMEMultipart('main')
self.attachments = []
def mailfrom(self, mail_from) :
self._from = mail_from
self.mail['from'] = mail_from
def mailto(self, mail_to) :
"""
mail_to : comma separated emails or a list
"""
if type(mail_to) == list:
self.mail['to'] = ','.join(mail_to)
self._to = mail_to
elif type(mail_to) == str :
self.mail['to'] = mail_to
if mail_to.find(',') > 0 :
self._to = [s.strip() for s in mail_to.split(',')]
else :
self._to = mail_to
else :
raise Exception('invalid mail to')
def mailsubject(self, mail_subject) :
self.mail['subject'] = mail_subject
def mailbody(self, mail_body) :
self.mail.attach(email.MIMEText.MIMEText(mail_body, 'plain', 'utf-8'))
def addattach(self, filepath, mime_type = 'octect-stream', rename = None) :
import os
f = open(filepath, 'rb')
filecontent = f.read()
f.close()
mb = email.MIMEBase.MIMEBase('application', mime_type)
mb.set_payload(filecontent)
email.Encoders.encode_base64(mb)
fn = os.path.basename(filepath)
self.mail.add_header('Content-Disposition', 'attachment', filename = rename or fn)
self.mail.attach(mb)
def send(self):
self.mail['Date'] = email.Utils.formatdate( )
Ïà¹ØÎĵµ£º
Õâ¸öÊÇ1.10°æ±¾µÄ²ÂÊý×Ö£¬ËäÈ»´úÂë»ù±¾²»±ä£¬µ«ÊDZäµÄÊÇ˼ά·½Ê½£¬²»ÔÙÊÇÓÃÃæÏò¹ý³ÌµÄ·½·¨£¬¶ø¸ÃΪÓÃÀàÀ´ÊµÏÖ£¬±È½ÏÇ°ºóµÄ´úÂ룬ÕâÒ»¸ö¼ò½à¶àÁË£¬¶øÇÒ¸üÈÝÒ×Àí½â£¡
¸üУº
#1.0°æ±¾ÖеÄÌáʾÀàÐÍÊÇ£ºAABB£¬¼òµ¥µÄ˵¾ÍÊÇÏà¶ÔλÖõÄÊý×Ö¶ÔÁ˾ÍÏÔʾA£¬´íÁ˾ÍÏÔʾB£»
#ÏÖÔÚµÄÌáʾ¸ÄΪ£º0A4B¸ñʽ£¬Ò²¾ÍÊÇ˵²»ÌáʾÄǸöλÖõÄÊý× ......
ÔÚparamikoÖÐʹÓÃÓû§ÃûºÍÃÜÂëͨ¹ýsftp´«ÊäÎļþ£¬²»Ê¹ÓÃkeyÎļþ¡£
import getpass
import select
import socket
import traceback
import paramiko
def putfile():
#import interactive
# setup logging
paramiko.util.log_to_file('demo.log')
username = username
hostname = hostname
......
¼òµ¥¼ÓÃÜ£¬ÓÃpythonÀ´Ð´Ð´¡£
#coding=utf-8
'''
Description: ¿ÉÄæµÄ¼ÓÃÜÓë½âÃÜ
Environment: python2.5.x
Author:idehong@gmail.com
'''
import os
import sys
class Code(object):
'''¿ÉÄæµÄ¼ÓÃÜÓë½âÃÜ'''
def __init__(self, key = "idehong@gmail.com"):
self.__src_key ......
1. Python ´®¿ÚÉ豸ӦÓÃ
¼òÊö
1.1. Ïß³ÌÂÖÑ°
·ç³¾ÎÞÏÞ <tianyu263@163.com>
-- ·ÖÏí
¾ÍÊÇ´ò¿ª´®¿Úºó£¬Æô¶¯Ò»¸öÏß³ÌÀ´¼àÌý´®¿ÚÊý¾ÝµÄ½øÈ룬ÓÐÊý¾Ýʱ£¬¾Í×öÊý¾ÝµÄ´¦Àí£¨Ò²¿ÉÒÔ·¢ËÍÒ»¸öʼþ£¬²¢Ð¯´ø½ÓÊÕµ½µÄÊý¾Ý£©¡£
Toggle line numbers
1
2 #coding=gb18030
3
4 i ......