Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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ÓïÑÔÓëÉè¼ÆÄ£Ê½

 Éè¼ÆÄ£Ê½ÊÇÒ»¸ö³éÏó²ã´Î£¬ÃèÊöÁËÔÚÒ»¸öÌØ¶¨µÄ»·¾³ÖÐÓÃÀ´½â¾öÒ»°ãÉè¼ÆÎÊÌâµÄ¶ÔÏóºÍÀàÖ®¼äµÄ½»»¥¹ØÏµ£¬ÆäÖ÷ҪĿµÄÊdzä·ÖÀûÓÃÓïÑÔµÄÌØÐÔ£¬Éè¼Æ¿É¸´Óõġ¢Äܹ»ÊÊÓ¦ÐèÇó±ä¸üµÄÈí¼þ[9]¡£Éè¼ÆÄ£Ê½ÊÇÒ»ÖÖÉè¼ÆË¼Ï룬ÓïÑÔÊÇʵÏÖ˼ÏëµÄ¹¤¾ß¡£Òò´Ë£¬²»Í¬ÓïÑÔµÄÌØÐÔÓ°ÏìÁËÉè¼ÆÄ£Ê½µÄʵÏÖ£¬ÓÐЩÓïÑÔ¸üÈÝÒ×ʵÏÖÉè¼ÆÄ£Ê½£¬¶øÓÐЩÓïÑÔÔ ......

PythonµÄASCII, GB2312, Unicode , UTF 8

PythonµÄASCII, GB2312, Unicode , UTF-8
ASCII ÊÇÒ»ÖÖ×Ö·û¼¯,°üÀ¨´óСдµÄÓ¢ÎÄ×Öĸ¡¢Êý×Ö¡¢¿ØÖÆ×Ö·ûµÈ£¬ËüÓÃÒ»¸ö×Ö½Ú±íʾ£¬·¶Î§ÊÇ 0-127 Unicode·ÖΪUTF-8ºÍUTF-16¡£
UTF-8±ä³¤¶ÈµÄ£¬×î¶à 6 ¸ö×Ö½Ú£¬Ð¡ÓÚ 127 µÄ×Ö·ûÓÃÒ»¸ö×Ö½Ú±íʾ£¬Óë ASCII ×Ö·û¼¯µÄ½á¹ûÒ»Ñù£¬ASCII ±àÂëϵÄÓ¢ÓïÎı¾²»ÐèÒªÐ޸ľͿÉÒÔµ±×÷ UTF-8 ±àÂë ......

Python Á·Ï°2

Éú³ÉÒ»¸öÓÐN¸öÔªËØµÄÓÐËæ»úÕûÊýn×é³ÉµÄÁÐ±í£¬ÆäÖÐNºÍÄêµÄȡֵ·¶Î§ÊÇ£¨1<N<=5£©
ºÍ(0<=n<100)£¬ÏÔʾÕâ¸öÁбíµÄËùÓÐ×Ó¼¯¡£
N¸öÊý×Ö¿ÕÓÐ2en¸ö×Ó¼¯£¬¶ÔÓÚÕâN¸öÊý×ÖÔÚÿ¸ö×Ó¼¯ÖÐÀ´½²ÒªÃ´´æÔÚҪô²»´æÔÚ£¬¿ÉÒÔ²ÉÓÃ×Ó¼¯Ó³ÉäΪ2½øÖƵÄËã·¨¡£
ÀýÈç[a,b]¼¯ºÏµÄ×Ó¼¯£º
¿Õ      ---- &nb ......

¹ØÓÚPythonÖÐÒ»Öֻص÷·½Ê½µÄʵÏÖ

#¹ØÓڻص÷¹¦ÄܵIJâÊÔ
#FunctorÊÇÕâÖֻص÷¹¦ÄܵĹؼü¶ÔÏó
class Functor:
    """Simple functor class."""
    def __init__( self, fn, *args ):
        self.fn = fn
        ......

beginning python summary chapter 4 ×Öµä

1¡¢PythonÖ®ÖÐΨһÄÚ½¨µÄÓ³ÉäÀàÐ;ÍÊÇ×ֵ䣨Dictionary£©¡£×ÖµäÖеÄÖµ²¢Ã»ÓÐÌØÊâµÄ˳Ðò£¬µ«ÊǶ¼°´Õչؼü×Ö£¨Key£©½øÐд洢£¬¹Ø¼ü×Ö¿ÉÒÔÊÇÊý×Ö¡¢×Ö·û´®£¬ÉõÖÁÊÇÔª×飨Tuple£©¡£
2¡¢×ÖµäµÄÓï·¨£º×ÖµäÃû = {'¼ükeys':'Öµvaules','¼ükeys':'Öµvaules','¼ükeys':'Öµvaules',...}£¬×ÖµäÖаüº¬ºÜ¶à¶Ô£¨³ÆÎªÌõÄ¿items£©£¬ÓÉ£¨keys£ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ