日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 在python的class中的,self到底是什么?

發布時間:2025/3/19 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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到底是什么?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。