1. 程式人生 > >python相關小技巧(保持更新)

python相關小技巧(保持更新)

HA top 就是 method python 函數定義 blog 解決 div

1、查看導入庫的類屬性、方法

python有一點感覺特別不方便的就是,不像C++指定了類型後,該類型的實例打個“.”會智能提示它含有的方法或屬性

之前都是靠查看庫對應的官方文檔解決。這次才發現了一個新方法 help,可以列出方法和屬性了

import dlib
help(dlib.rectangles)

Help on class rectangle in module dlib:

class rectangle(pybind11_builtins.pybind11_object)
 |  This object represents a rectangular area of an image.
 |  
 |  Method resolution order:
 |      rectangle
 |      pybind11_builtins.pybind11_object
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  __eq__(...)
 |      __eq__(self: dlib.rectangle, arg0: dlib.rectangle) -> bool
 |  
 |  __getstate__(...)
 |      __getstate__(self: dlib.rectangle) -> tuple
 |  
 |  __init__(...)
 |      __init__(self: dlib.rectangle, left: int, top: int, right: int, bottom: int) -> None
 |  
 |  __ne__(...)

2、跳轉至函數定義的源代碼處

使用pycharm,按住CTRL,點擊函數,會跳轉至函數定義處

3、定義定長數組

import numpy as np
highlights_add = highlights_sub = np.zeros(256, dtype=np.float64)

python相關小技巧(保持更新)