python 在python的class中的,self到底是什么?
生活随笔
收集整理的這篇文章主要介紹了
python 在python的class中的,self到底是什么?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
self可理解成一個用于存儲類實例化前后的對象的屬性和方法的入口
屬性是對象的屬性,方法是對象的方法
如在一個線程類中:
# 【類】單個攝像頭線程 class CamThread(threading.Thread):def __init__(self, thread_id, name, cam_serial):threading.Thread.__init__(self)self.thread_id = thread_idself.cam_serial = cam_serialself.name = namedef run(self):print('攝像頭{}線程{}啟動:'.format(self.cam_serial, self.name))# 配置攝像頭并啟動流# self.cam_cfg(self.cam_serial) # 放函數里就不行了不知為什么?locals()['pipeline' + self.cam_serial] = rs.pipeline(ctx)locals()['config' + self.cam_serial] = rs.config()locals()['config' + self.cam_serial].enable_device(self.cam_serial)locals()['config' + self.cam_serial].enable_stream(rs.stream.depth, 1280, 720, rs.format.z16, 30)locals()['config' + self.cam_serial].enable_stream(rs.stream.color, 1280, 720, rs.format.bgr8, 30)locals()['pipeline' + self.cam_serial].start(locals()['config' + self.cam_serial])locals()['align' + self.cam_serial] = rs.align(rs.stream.color)# 從內存循環讀取攝像頭傳輸幀try:while True:locals()['frames' + self.cam_serial] = locals()['pipeline' + self.cam_serial].wait_for_frames()locals()['aligned_frames' + self.cam_serial] = locals()['align' + self.cam_serial].process(locals()['frames' + self.cam_serial])locals()['aligned_depth_frame' + self.cam_serial] = locals()['aligned_frames' + self.cam_serial].get_depth_frame()locals()['color_frame' + self.cam_serial] = locals()['aligned_frames' + self.cam_serial].get_color_frame()locals()['color_profile' + self.cam_serial] = locals()['color_frame' + self.cam_serial].get_profile()locals()['cvsprofile' + self.cam_serial] = rs.video_stream_profile(locals()['color_profile' + self.cam_serial])locals()['color_intrin' + self.cam_serial] = locals()['cvsprofile' + self.cam_serial].get_intrinsics()locals()['color_intrin_part' + self.cam_serial] = [locals()['color_intrin' + self.cam_serial].ppx,locals()['color_intrin' + self.cam_serial].ppy,locals()['color_intrin' + self.cam_serial].fx,locals()['color_intrin' + self.cam_serial].fy]locals()['color_image' + self.cam_serial] = np.asanyarray(locals()['color_frame' + self.cam_serial].get_data())cv2.imshow('{}'.format(self.cam_serial), locals()['color_image' + self.cam_serial])key = cv2.waitKey(1)finally:print('攝像頭{}線程{}結束:'.format(self.cam_serial, self.name))參考文章:在python的class中的,self到底是什么?
總結
以上是生活随笔為你收集整理的python 在python的class中的,self到底是什么?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 运算符 (算术运算符、比较
- 下一篇: Leetcode python《热题 H