Python 命令行帮助文档工具

python内置了很多内置函数、类方法属性及各种模块。当我们想要当我们想要了解某种类型有哪些属性方法以及每种方法该怎么使用时,我们可以使用dir()函数和help()函数,在python ide交互式模式下获得我们想要的帮助信息。

dir()

dir()用来查询一个类或者对象所有属性,比如:

>>> dir(list) #或 dir(['a', 'b'])
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>>

help()

help()函数帮助我们了解模块、类型、对象、方法、属性的详细信息。

1. 帮助查看类型详细信息,包含类的创建方式、属性、方法

>>> from selenium.webdriver.common.by import By
>>> help(By)
Help on class By in module selenium.webdriver.common.by:

class By(builtins.object)
 |  Set of supported locator strategies.
 |
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)
 |
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |
 |  CLASS_NAME = 'class name'
 |
 |  CSS_SELECTOR = 'css selector'
 |
 |  ID = 'id'
 |
 |  LINK_TEXT = 'link text'
 |
 |  NAME = 'name'
 |
 |  PARTIAL_LINK_TEXT = 'partial link text'
 |
 |  TAG_NAME = 'tag name'
 |
 |  XPATH = 'xpath'

>>>

2.帮助查看方法的详细使用信息(使用时要注意输入完整路径,使用模块帮助时,需要先导入模块)

查看python所有的关键字:help("keywords")

查看python所有的modules:help("modules")

单看python所有的modules中包含指定字符串的modules: help("modules yourstr")

查看python中常见的topics: help("topics")

查看python标准库中的module:import os.path + help("os.path")

查看python内置的类型:help("list")

查看python类型的成员方法:help("str.find") 

查看python内置函数:help("open")

查看python全局或内置方法:dir(__builtins__)

查看python内置模块的信息:help(__builtins__)

3.查看帮助过程中,需要退出帮助信息,请输入CTRL+C

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值