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

python学习网 2018-03-20 07:28:01

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)

 

阅读(753) 评论(0)