Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : Python

python·¢ÓʼþµÄ´úÂë

# -*- coding: cp936 -*-
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib
 
#´´½¨Ò»¸ö´ø¸½¼þµÄʵÀý
msg = MIMEMultipart()
#¹¹Ô츽¼þ
att = MIMEText(open('e:\\test.txt').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/octet-stream'
#att["Content-Disposition"] = 'attachment; filename="e:\\test.txt"' ÒÔ¸½¼þÐÎʽ·¢ËÍ
msg.attach(att)
mailto_list=["wsywfw3@163.com"]
#####################
# ÉèÖ÷þÎñÆ÷£¬Óû§Ãû¡¢¿ÚÁîÒÔ¼°ÓÊÏäµÄºó׺
mail_host="smtp.163.com"
mail_user="wsywfw3@163.com"
mail_pass="7451920"
mail_postfix="163.com"
######################
def send_mail(to_list,sub,content):
    '''
    to_list:·¢¸øË­
    sub:Ö÷Ìâ
    content:ÄÚÈÝ
    send_mail("aaa@126.com","sub","content")
    '''
    ......

python ÃüÁîÐвÎÊý


±¾Æª½«½éÉÜpythonÖÐsys, getoptÄ£¿é´¦ÀíÃüÁîÐвÎÊý
Èç¹ûÏë¶Ôpython½Å±¾´«²ÎÊý£¬pythonÖжÔÓ¦µÄargc, argv(cÓïÑÔµÄÃüÁîÐвÎÊý)ÊÇʲôÄØ£¿
ÐèҪģ¿é£ºsys
²ÎÊý¸öÊý£ºlen(sys.argv)
½Å±¾Ãû£º    sys.argv[0]
²ÎÊý1£º     sys.argv[1]
²ÎÊý2£º     sys.argv[2]
test.py
1
import sys
2
print "½Å±¾Ãû£º", sys.argv[0]
3
for i in range(1, len(sys.argv)):
4
    print "²ÎÊý", i, sys.argv[i]
>>>python test.py hello world
½Å±¾Ãû£ºtest.py
²ÎÊý 1 hello
²ÎÊý 2 world
pythonÖÐʹÓÃÃüÁîÐÐÑ¡Ï
ÀýÈçÎÒÃÇÐèÒªÒ»¸öconvert.py½Å±¾¡£ËüµÄ×÷ÓÃÊÇ´¦ÀíÒ»¸öÎļþ,²¢½«´¦ÀíºóµÄ½á¹ûÊä³öµ½ÁíÒ»¸öÎļþÖС£
ÒªÇó¸Ã½Å±¾Âú×ãÒÔÏÂÌõ¼þ£º
1.ͨ¹ý-i -oÑ¡ÏîÀ´Çø±ð²ÎÊýÊÇÊäÈëÎļþ»¹ÊÇÊä³öÎļþ.
>>> python convert.py -i inputfile -o outputfile
2.µ±²»ÖªµÀconvert.pyÐèÒªÄÄЩ²ÎÊýʱ£¬ÓÃ-h´òÓ¡³ö°ïÖúÐÅÏ¢
>>> python convert.py -h
getoptº¯ÊýÔ­ÐÎ:
getopt.getopt(args, options[, long_options])
convert.py
01
import sys, geto ......

PythonµÄbug

PythonÌ«»ðÁË£¬²»Ñ§µã¶¼¸Ð¾õ×Ô¼º²»ÊÇѧ¼ÆËã»úµÄ£¬½ñÌì¿´Á˸ö²»´íµÄ¡¶¼òÃ÷python½Ì³Ì¡·£¬ºÜ²»´í¡£²»¹ýÔÚѧϰ¹ý³ÌÖУ¬¾ÓÈ»·¢ÏÖÁËÒ»¸öPythonµÄbug£¬
#!/usr/bin/python
#coding=UTF-8
class Person:
'''Represents a person.'''
population = 0
def __init__(self, name):
'''Initializes the person's data.'''
self.name = name
print '(Initializing %s)' % self.name
Person.population += 1
def __del__(self):
'''I am dying'''
print '%s syas bye.' % self.name
Person.population -= 1
if Person.population == 0:
print 'I am the last one.'
else:
print 'There are still %d people left.' % \
Person.population
def sayHi(self):
'''Greeting by the person.
Really, that's all it does'''
print 'Hi, my name is %s.' % self.name
def howMany(self):
'''Prints the current population'''
if Person.population == 1:
print "I am the only person here"
else:
print 'We have %d persons here.' % Person.population
luolei = Person('luolei')
luolei.sayHi()
luolei. ......

python ½Å±¾ £­ ×Ô¶¯¼ì²â´úÀíËÙ¶È

Õâ¸ö½Å±¾ÊÇÔÚ python »·¾³ÏÂʹÓõģ¬¸ÄµÄÍøÉϵÄÒ»¸ö½Å±¾£¬¿ÉÒÔ¼ì²â´úÀíÖйú£¨www.proxycn.com£©ÉϵÄHTTP´úÀíÁÐ±í£¬ÄãÒ²¿ÉÒÔ×Ô¼ºÈ¥ÉÏÃæÕÒÁбí¼ì²â ´úÂë: #!/usr/bin/python # -*- coding: utf-8 -*- # from: ubuntu.org.cn Copyright: GPLv2 import urllib import re from datetime import datetime import socket def findporxy(): url = "http://www.proxycn.com/html_proxy/http-1.html" f = urllib.urlopen(url) html = f.read() p = re.compile('clip\(\'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,4})\'\);') ips=set(p.findall(html)) socket.setdefaulttimeout(5) a={} for ip in ips: start=datetime.now() flag = checkproxy(ip) end=datetime.now() if flag: print ip,'»¨·Ñ',end-start,'ʱ¼ä'; a[end-start]=ip b=sorted(a) print 'ËÙ¶ÈÅÅÐò :' i = 0 for ix in a: print 'No.',i,': ',a[b[i]] i = i + 1 def checkproxy(ip): try: proxies = {'http': 'http://'+ip} filehandle = urllib.urlopen("http://www.0x201.cn/moyo/speed_x.jpg", proxies=proxies) html=filehandle.read() if len(html)==80996: return True else: return False except: return Fals ......

ÔÚpythonÖд¦ÀíXML×ܽá

±¾ÎÄ×ܽáÁËÔÚPythonÖÐÖ÷ÒªµÄ¼¸ÖÖ´¦ÀíXMLµÄ·½·¨£º
Element Tree
SAX
Dom
ʹÓõÚÈý·½Àà¿âÈçAmara 2.x£¬ libxml2dom µÈ
Element Tree
Element TreeÊÇPython 2.5ÒýÈëµÄʹÓüòµ¥£¬¿ì½ÝµÄ´¦Àí·½·¨£¬ Ò²ÊÇPython±ê×¼Àà¿âÍƼöµÄ´¦ÀíXMLµÄ·½·¨¡£
ËüʹÓÃÊ÷ÐνڵãµÄÐÎʽÀ´¶ÁдXML¡£Element TreeÊÇÇáÁ¿¼¶µÄDOM£¬ ËùÒÔʹÓ÷½±ãÇÒºÄ×ÊÔ´ÉÙ¡£
±ÈÈçÓÐÒÔÏÂXMLÎļþ£º sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="001">
<name>John</name>
<age>25</age>
<phone>12345</phone>
</user>
<user id="002">
<name>Bill</name>
<age>30</age>
<phone>54321</phone>
</user>
<user id="003">
<name>Rex</name>
<age>35</age>
<phone>88888</phone>
</user>
</users> 
ʵÀý´úÂëÈçÏ£º
# -*- coding: utf-8 -*-
import sys
from xml.etree import Elem ......

ÔÚpythonÖд¦ÀíXML×ܽá

±¾ÎÄ×ܽáÁËÔÚPythonÖÐÖ÷ÒªµÄ¼¸ÖÖ´¦ÀíXMLµÄ·½·¨£º
Element Tree
SAX
Dom
ʹÓõÚÈý·½Àà¿âÈçAmara 2.x£¬ libxml2dom µÈ
Element Tree
Element TreeÊÇPython 2.5ÒýÈëµÄʹÓüòµ¥£¬¿ì½ÝµÄ´¦Àí·½·¨£¬ Ò²ÊÇPython±ê×¼Àà¿âÍƼöµÄ´¦ÀíXMLµÄ·½·¨¡£
ËüʹÓÃÊ÷ÐνڵãµÄÐÎʽÀ´¶ÁдXML¡£Element TreeÊÇÇáÁ¿¼¶µÄDOM£¬ ËùÒÔʹÓ÷½±ãÇÒºÄ×ÊÔ´ÉÙ¡£
±ÈÈçÓÐÒÔÏÂXMLÎļþ£º sample.xml
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user id="001">
<name>John</name>
<age>25</age>
<phone>12345</phone>
</user>
<user id="002">
<name>Bill</name>
<age>30</age>
<phone>54321</phone>
</user>
<user id="003">
<name>Rex</name>
<age>35</age>
<phone>88888</phone>
</user>
</users> 
ʵÀý´úÂëÈçÏ£º
# -*- coding: utf-8 -*-
import sys
from xml.etree import Elem ......

Eclipse»ùÓÚpython¡¢Django×öWeb¿ª·¢

 ÏȽ«ÉÏÃæ´´½¨ºÃµÄtestdemo¹¤³ÌĿ¼\£¬½«C:\Python25\Lib\site-packages\django\binÖеÄtestdemoĿ¼¿½±´µ½×Ô¼ºµÄ¹¤×÷Ŀ¼ÖУ¬È»ºóÆô¶¯eclipse£¬µã»÷“File”->“New”->“project…”£¬½«»á¿´µ½ÒÔÏ»­Ãæ
 
Ñ¡Ôñ“Pydev Project”£¬µã»÷“Next”
 
´´½¨Ò»¸öÓëtestdemoµÄ¹¤³Ì£¬Â·¾¶Ö¸ÏòÄãÔ­Éú³ÉµÄ¹¤³ÌĿ¼£¬Grammar VersionÑ¡Ôñ2.5µÄ°æ±¾£¬interpreter¶ÔÓ¦µÄҲҪѡÔñpython25£¬È¡ÏûϵͳÉú³ÉSrcĿ¼£¬µã»÷“finish”Íê³É´´½¨£¬ÔÚ¹¤³ÌĿ¼ÉϵãÓÒ¼ü£¬Ñ¡Ôñ“Refresh”£¬Ä㽫»áµ½Ô­Éú³ÉµÄÎļþ¡£
 
ÏÖÔÚÎÒÃÇÀ´×öһЩ²âÊÔ£¬ÏÈÀ´½¨Á¢Ò»¸ö×Ó¼¯
 
ÔÙË¢ÐÂһϹ¤³ÌĿ¼
 
ÎÒÃǽ«helloĿ¼ÏÂÏÖÔÚûÓõÄmodels.py¡¢tests.pyÁ½¸öÎļþɾ³ýµô£¬½«ÏÂÃæ´úÂëдÈëµ½hello\views.pyÖÐ
 
 
±à¼­testdemoĿ¼ÏµÄurls.py£¬ÄÚÈÝÈçÏ 
from django.conf.urls.defaults import *
urlpatterns = patterns('',
    (r'^$', 'testdemo.hello.views.index'),   
)
±£´æÎļþ£¬ÔËÐзþÎñ£ ......
×ܼǼÊý:695; ×ÜÒ³Êý:116; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [1] [2] [3] [4] 5 [6] [7] [8] [9] [10]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ