總結一下python網路編程中常用到的函數socket.getservbyname(servicename[, protocolname]) –> integer 查詢某個協議對應的連接埠號碼,需要使用兩個參數,servicename對應連接埠名稱,如 http, smtp,等。protocolname對應tcp,udp。s.getsockname()s.getpeername() getsockname: Return the address of the local
python的set和其他語言類似, 是一個無序不重複元素集, 準系統包括關係測試和消除重複元素. 集合對象還支援union(聯合), intersection(交), difference(差)和sysmmetric difference(對稱差集)等數學運算.sets 支援 x in set, len(set),和 for x in set。作為一個無序的集合,sets不記錄元素位置或者插入點。因此,sets不支援 indexing, slicing,
Python內建函數(14)——delattr,pythondelattr英文文檔:delattr(object, name) This is a relative of setattr(). The arguments are an object and a string. The string must be the name of one of the object’s attributes. The function deletes the named attribute,
自然語言處理3.6——正常化文本,自然語言處理3.6在前面的例子中,在處理文本詞彙前經常要將文本轉化成小寫,即(w.lower() for w in words).通過lower()將文本正常化為小寫,這樣一來,"The"和"the"的區別被忽略了。我們常常進行更多的嘗試,例如去掉文本中的所有詞綴已經提取詞乾的任務等。下一步是確保結果形式是字典中確定的詞,即詞形歸併任務。首先定義一下本節使用的資料。>>>raw="""DENNIS: Listen, strange women
Python內建函數(11)——classmethod,pythonclassmethod英文文檔:classmethod(function) Return a class method for function.A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method,
Python內建函數(12)——compile,pythoncompile英文文檔:compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)Compile the source into a code or AST object. Code objects can be executed by exec() or eval(). source can either be a normal string,
Python內建函數(9)——callable,pythoncallable英文文檔:callable(object) Return True if the object argument appears callable, False if not. If this returns true, it is still possible that a call fails, but if it is false, calling object will never succeed.
Python內建函數(10)——chr,python內建函數chr英文文檔:chr(i) Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a', while chr(8364) returns the string '€'. This is the inverse of