Python Á·Ï°3 ¶¨ÒåÀ࣬Àà·½·¨£¬ÊµÀý·½·¨
Éè¼ÆÒ»¸öIPÀࣺ
Éè¼Æ1 ÒªÇ󣺳õʼ»¯Ê±¸ø¶¨ipµØÖ·²¢ÅжÏipµØÖ·µÄºÏ·¨ÐÔ
Àà·½·¨£ºÅжÏipµØÖ·ºÏ·¨ÐÔ
ʵÀý·½·¨£º½«ipµØַת»¯Îª10½øÖƵıíʾÐÎʽ¼°16½øÖƵıíʾÐÎʽ
ÀýÈ磺192.168.168.8 Ê®½øÖÆÐÎʽΪ3232278536£¬Ê®Áù½øÖÆÐÎʽΪc0a8a808
Éè¼Æ2 ÒªÇó£ºÀ©Õ¹ÒªÇó1ÖÐipÀ࣬ʹÆäʵÀý»¯Ê±Ôö¼Ó×ÓÍøÑÚÂ붨Ò壬²¢ÔÚ³õʼ»¯ÊÇÅжÏ×ÓÍøÑÚÂëµÄºÏ·¨ÐÔ
ʵÀý·½·¨£º»ñÈ¡ipËùÊô×ÓÍøµÄÍøÂçºÅ£¬¹ã²¥µØÖ·£¬¼°×ÓÍøÄÚip¸öÊý
Éè¼Æ1½âÎö£º
"""Ip address analyzer
Method:
dispIp: Display ip address.
intIp: Get integer of ip address.
hexIp: Get hex of ip address"""
from string import Template
class IpAddress(object):
'Ip address analyzer'
def __init__(self,ip):
'Initialize ip address and netmask'
assert IpAddress.isIp(ip),\
"ip is invalid"
self.ipAddr = ip
def isIp(cls,x):
'Determine if the ip address is valid'
aList = x.split(".")
if len(aList) != 4:
return False
else:
nList=[i for i in aList if (i.isdigit() and 0 <= int(i) <= 255)]
if len(nList) != 4: return False
else: return True
isIp=classmethod(isIp)
def __bin(self,x):
'Convert the decimal into binary,and return 8-bit binary. '
x = int(x)
if x == 0:
return '00000000'
else:
re = ''
while x > 0:
mod = x%2
x = x/2
re = str(mod) + re
differ = 8 - len(re)
re = ''.join(['0' for i in range(differ)]) + re
return re
def dispIp(self):
'Display ip address'
template = Template('IP: ${ipAddr}')
print template.substitute(ipAddr=self.ipAddr)
def intIp(self):
'Return integer of the ip address'
aList = self.ipAddr.split(".")
str2 = ''.join(self.__bin(i) for i in aList)
return str(int(str2, 2))
def hexIp(self):
'Return hex of the ip address'
aList = self.ipAddr.split(".")
retu
Ïà¹ØÎĵµ£º
ÔÚ pythonµÄlibĿ¼ÀïÓÐÒ»¸ö£ºthis.py£¬ËüÆäʵÊÇÒþ²Ø×ÅÒ»Ê×Ê«£¬Ô´ÂëÈçÏ£º
s =
"""Gur Mra bs Clguba, ol Gvz Crgref
Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf ......
# -*- coding: utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup, Tag
import re
page = urllib2.urlopen("http://bj.ganji.com/piao/zz_%E5%8C%97%E4%BA%AC-%E5%8D%97%E6%98%8C/20100210/")
soup = BeautifulSoup(page)
#ss = soup.findAll('a', href=re.compile(r"^/piao/100.&qu ......
½âѹdjango£¬È»ºóµ½ÆäĿ¼Ï°²×°
Ç°ÌáÊÇÄã°²×°ºÃpython.²¢½«ÆäÅäÖõ½»·¾³±äÁ¿ÖУ¬È»ºóÈ¥djangoµÄѹËõÎÄÐÞµÄÏ£¬Ö´ÐÐÒÔϵ¹ÃüÁî
python setup.py install
1.´´½¨project
Ê×ÏÈÎÒÃÇ´ò¿ªcmd, ¶¨Î»µ½Ï£Íûн¨¹¤³ÌµÄĿ¼ÏÂ, ÈÎÒâĿ¼¾ù¿É. È»ºó¼üÈëÈçÏÂÃüÁî:
django-admin.py startproject helloÆäÖÐhelloΪй¤³ÌĿ¼ÎļþÃû ......
#¹ØÓڻص÷¹¦ÄܵIJâÊÔ
#FunctorÊÇÕâÖֻص÷¹¦ÄܵĹؼü¶ÔÏó
class Functor:
"""Simple functor class."""
def __init__( self, fn, *args ):
self.fn = fn
  ......
1¡¢PythonÖ®ÖÐΨһÄÚ½¨µÄÓ³ÉäÀàÐ;ÍÊÇ×ֵ䣨Dictionary£©¡£×ÖµäÖеÄÖµ²¢Ã»ÓÐÌØÊâµÄ˳Ðò£¬µ«ÊǶ¼°´Õչؼü×Ö£¨Key£©½øÐд洢£¬¹Ø¼ü×Ö¿ÉÒÔÊÇÊý×Ö¡¢×Ö·û´®£¬ÉõÖÁÊÇÔª×飨Tuple£©¡£
2¡¢×ÖµäµÄÓï·¨£º×ÖµäÃû = {'¼ükeys':'Öµvaules','¼ükeys':'Öµvaules','¼ükeys':'Öµvaules',...}£¬×ÖµäÖаüº¬ºÜ¶à¶Ô£¨³ÆΪÌõÄ¿items£©£¬ÓÉ£¨keys£ ......