Python_ Static Object _socket

Source: Internet
Author: User

Object-oriented programming advancedStatic methods Add Staticmethod After this function is still in the class, but it is not related to the class, and no need to call self Direct D = Dog ("Chenronghua") D.eat (d)   Example:Class Dog (object): Def __init__ (self, Name,): Self.name = name @staticmethod # This will cause an error when the Self def eat (self) is missing: Print ("%s is eating"% (self.name)) d = Dog ("Chen Ronghua") d.eat () typeerror:eat () Missing 1 required positional argument: ' Self class MethodClass methods can only access analog variables Property MethodTurn a method into a static property class Dog: Def __init__ (self, Name,): Self.name = name @property #attribute def Eat (self): print ("%s is eating"%self.name) d = Dog ("Chenronghua") d.eat special member methods for classes   __doc__#直接打印这个类的描述class Foo (object): "" "This class is a description of the dog object" "" Print (foo.__doc__) __module__ and __class____MODULE__ represents the current operation of the object in that module __class__ represents the current object's class is what the __call__ object is appended with parentheses, triggering executionClass Dog (object): Def __cal__ (self, *args, *kwargs) d = Dog ("Chenronghua") d (1,2,3,name= "3333") __dict__ Print the property class D OG (object): Def __cal__ (self, *args, *kwargs) d = Dog ("Chenronghua") d (1,2,3,name= "3333") #打印类里的属性print dog.__dict__# Print Method in D print d.__dict__ ReflectionHasattr (OBJ,NAME_STR)   getattr (obj_name_str)  class Dog (object):     def __init__ ( Self, name):        Self.name = name     def eat (self):        Prin T ("%s is eating ..."%self.name)  d = Dog ("niu") choice = input (">>:"). Strip () if Hasattr (d,choice):             #判断对象里是否有对应的字符串的方法映射     func = GetAttr (d,choice)     #根据字符串里的对象去获取对 Method memory address     func ("Chenronghua")   def Bulk (name):      print ("%s da Jiao "%name)    class Dog (object):    def __init__ (self, name):        Self.name = name     def eat (Self,food):        print ("%s eat%s"% (Self.name,food))  d = Dog ("Niuhanyang") # d.eat ("Chenronghua")  def Bulk (self):    print ("Yell%s"%self.name)  choice = input (">& Gt : ")  if hasattr (d,choice):    PRInt (hasattr (d,choice))     GetAttr (D,choice) ("Grass") else:    SetAttr (d,choice,bulk)     GetAttr (D,choice) (d)     #func = GETATTRT (d,choice)     #func (d)    SOCKETCONN,ADDR = Server.accept () conn is a client connecting to the server for which an instance is generated addr is an IP address and port

Python_ Static Object _socket

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.