类工具以及实例工具
冗长实践:(保举学习:Python视频教程)
类工具是将具备类似属性以及办法的工具总结形象为类工具,能够界说类似的一些属性以及办法,没有同的实例工具去援用类工具的属性以及办法,能缩小代码的反复率。
实例工具又称实例化工具,没有是形象而是一类工具中详细的一例工具。
比喻了解:
我置信有的人感觉有点绕,正在这里我以比喻阐明,心愿你能明确。起首,要明确,正在python中,“万物皆工具”。集体了解:
类工具,好比有一篮“生果”,篮子外面的生果不反复,那末这一篮中的“生果”就属于一个类,是形象的,就像有人对你说“给我生果”,你的第一反响肯定是“甚么生果?”,以是是没有确定性的。
实例工具,好比篮子外面的“苹果”,是一个详细的工具,即一个实例。我想有人对你说“给我苹果”,你应该没有会想抉择哪一个生果吧
class Main_class_dll(): def __init__(self): dllName = "SessionConnector.dll" dllABSPath = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + dllName self.dll = cdll.LoadLibrary(dllABSPath) self.session_id='' def int_create_(self): self.dll.Init.restype = c_bool sign = self.dll.Init() def Create_Session(self,ip,port): self.dll.CreateSession.argtypes=[c_char_p,c_char_p] #输出参数的格局 self.dll.CreateSession.restype = c_int; #输入参数的格局 self.session_id = self.dll.CreateSession(ip,port); def send_recv(self,buf): time.sleep(2) self.dll.SendSessionMsg.restype = c_bool; self.dll.SendSessionMsg.argtypes=[c_int,c_char_p,c_uint] ret = self.dll.SendSessionMsg(self.session_id, buf, len(buf) + 1); self.dll.RecvSessionMsg.argtypes=[c_int,c_char_p,c_uint,c_int] self.dll.RecvSessionMsg.restype = c_bool; recv_buf = create_string_buffer(1024); ret = self.dll.RecvSessionMsg(self.session_id, recv_buf, 1024, 3000); self.dll.DestroySession.restype = c_bool; ret = self.dll.DestroySession(self.session_id); return recv_buf.value
类工具就是能够用类名字间接应用示意的工具,它支持两种操作,间接属性应用以及实例化。关于类属性的应用,间接应用类名.属性便可。关于类办法的应用,需求实例化一个工具后,将工具名赋值给self应用,以下所示:
class test: data = 1 def __init__(self): self.property=0 def test2(self): print 'hello' if __name__=='__main__': t = test() print test.data print t.data print test.test2 print t.test2() print test.test2(t)
更多Python相干技巧文章,请拜访Python教程栏目进行学习!
以上就是Python类工具实例工具的区分的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!