Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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


Ïà¹ØÎĵµ£º

UltraEdit»·¾³pythonÓï·¨¸ßÁÁÉèÖÃ

ÎÒÒ»Ö±ÔÚÓÃultraedit¿´zope3µÄÔ´´úÂë.Óï·¨¸ßÁÁÉèÖÿɲο¼www.ultraedit.com
UltraEditÊÇÒ»¸öºÜºÃµÄ¹¤¾ß£¬µ«ÊÇĬÈϲ»Ö§³ÖPythonµÄÓï·¨¸ßÁÁ£¬ÏÂÃæÊÇÒ»¸öÏֳɵÄWordFileƬ¶Ï£¬°ÑÕâ¶ÎÎÄ×ÖCopyµ½UltraEditÏÂÃæµÄWORDFIL E.TXTÎļþÖУ¬±£´æºó¾Í¿ÉÒÔ¿´µ½UltraEdit¶ÔPythonÎļþºÍÓï·¨µÄÖ§³ÖÁË^_^£¨×¢Ò⣬°Ñ/L11¸ÄΪÄãµÄWordfileµÄ ......

PythonÖ´ÐÐϵͳÃüÁîµÄ·½·¨

PythonÖÐÖ´ÐÐϵͳÃüÁî³£¼û·½·¨ÓÐÁ½ÖÖ£º
Á½Õß¾ùÐè import os
(1) os.system
# ½ö½öÔÚÒ»¸ö×ÓÖÕ¶ËÔËÐÐϵͳÃüÁ¶ø²»ÄÜ»ñÈ¡ÃüÁîÖ´ÐкóµÄ·µ»ØÐÅÏ¢
system(command) -> exit_status   
Execute the command (a string) in a subshell. 
# Èç¹ûÔÙÃüÁîÐÐÏÂÖ´ÐУ¬½á¹ûÖ±½Ó´òÓ¡³öÀ´
>>> os. ......

PythonÎļþµÄ¶Áд

Ïà±Èjava¶øÑÔ£¬PythonÓü¸ÐдúÂë¾Í¿ÉÒÔ´úÌæjavaÊ®À´ÐеĴúÂë£¬ÕæµÄ·Ç³£²»´í
'''
Created on 2009-9-2
@author: jiangqh
'''
# file create and write
context = '''hello world
hello china '''
f = file("hello.txt",'w')
f.write(context)
f.close()
Îļþ´´½¨
#use readline() read file
f = o ......

¹ØÓÚ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ºÅ