专栏首页python3python中3个帮助函数help,di

python中3个帮助函数help,di

1 help函数:查看模块、函数、变量的详细说明:

  • 查看模块
>>> help("modules")

Please wait a moment while I gather a list of all available modules...

BaseHTTPServer      array               htmllib             sets
Bastion             ast                 httplib             sgmllib
CDROM               asynchat            ihooks              sha
CGIHTTPServer       asyncore            imaplib             shelve
Canvas              atexit              imghdr              shlex
ConfigParser        audiodev            imp                 shutil
Cookie              audioop             importlib           signal
DLFCN               axi                 imputil             site
Dialog              base64              inspect             sitecustomize
DocXMLRPCServer     bdb                 io                  smtpd
FileDialog          binascii            itertools           smtplib
  • 查看包
>>> help("json")
Help on package json:

NAME
    json

FILE
    /usr/lib/python2.7/json/__init__.py

MODULE DOCS
    http://docs.python.org/library/json

DESCRIPTION
    JSON (JavaScript Object Notation) <http://json.org> is a subset of
    JavaScript syntax (ECMA-262 3rd edition) used as a lightweight data
    interchange format.
    
    :mod:`json` exposes an API familiar to users of the standard library
    :mod:`marshal` and :mod:`pickle` modules. It is the externally maintained
    version of the :mod:`json` library contained in Python 2.6, but maintains
    compatibility with Python 2.4 and Python 2.5 and (currently) has
    significant performance advantages, even without using the optional C
    extension for speedups.
    
    Encoding basic Python object hierarchies::
  • 查看类
>>> help(json.JSONDecoder)
Help on class JSONDecoder in module json.decoder:

class JSONDecoder(__builtin__.object)
 |  Simple JSON <http://json.org> decoder
 |  
 |  Performs the following translations in decoding by default:
 |  
 |  +---------------+-------------------+
 |  | JSON          | Python            |
 |  +===============+===================+
 |  | object        | dict              |
 |  +---------------+-------------------+
 |  | array         | list              |
 |  +---------------+-------------------+
 |  | string        | unicode           |
 |  +---------------+-------------------+
 |  | number (int)  | int, long         |
 |  +---------------+-------------------+
 |  | number (real) | float             |
 |  +---------------+-------------------+
 |  | true          | True              |
 |  +---------------+-------------------+
 |  | false         | False             |
  • 查看函数:
>>> help(json.dump)
Help on function dump in module json:

dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding='utf-8', default=None, **kw)
    Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
    ``.write()``-supporting file-like object).
    
    If ``skipkeys`` is true then ``dict`` keys that are not basic types
    (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
    will be skipped instead of raising a ``TypeError``.
    
    If ``ensure_ascii`` is false, then the some chunks written to ``fp``
    may be ``unicode`` instances, subject to normal Python ``str`` to
    ``unicode`` coercion rules. Unless ``fp.write()`` explicitly
    understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
    to cause an error.

2 dir函数:查看变量可用的函数或方法

>>> import sys
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'exitfunc', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'hexversion', 'last_traceback', 'last_type', 'last_value', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2', 'py3kwarning', 'pydebug', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions']

3 type函数:查看变量的类型

<type 'module'>
>>> type (json.__name__)
<type 'str'>
>>> type (json.decoder)
<type 'module'>

4 退出python命令行

windows: ctrl+z 回车

linux:ctrl+d 

注:使用pydoc module 可查看模块的文档说明

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Python判断对象是否是functio

    有时候用python就有这么一种感悟,各种钩子函数就是通过内置的“__”属性实现,python学得好不好,就是对“__”属性理解得透彻不透彻。

    py3study
  • Python整型:布尔型、标准整型、长整

    py3study
  • python学习(11)

    位置参数 传入参数顺序 、个数必须一致 def add(a,b): return a + b

    py3study
  • QueueUserAPC function

    Adds a user-mode asynchronous procedure call (APC) object to the APC queue of th...

    战神伽罗
  • SAP CRM中间件错误IB_CRM_UPLOAD_MSG的解决方法

    I have one parent equipment ZJERRY0827P which contains a children equipment ZJER...

    Jerry Wang
  • CONSAC:基于条件样本一致性的鲁棒多模型拟合(CS CV)

    本文提出了一种基于噪声测量的多参数模型的鲁棒估计方法。应用包括在人造场景中寻找多个消失点,将平面拟合到建筑图像中,或在同一序列中估计多个刚性运动。与以往的多模型...

    DANDAN用户6837186
  • IronPython 2.0 beta 5

    ironpython 2.0 beta 5 已经发布,下载地址:http://www.codeplex.com/IronPython/Release/Proje...

    张善友
  • 控制动态学习排名中的公平和偏差(CS IR)

    排名是许多在线平台将用户与物品(如新闻、产品、音乐、视频)进行匹配的主要界面。在这些两面性市场中,不仅用户从排名中汲取效用,而且排名也决定了物品提供者(如出版商...

    刘持诚
  • Nebula3的渲染流程

    每帧的渲染过程都写进了配置文件, 默认使用的是"frame/win32/dx9default.xml", 阴影还有另外一套.

    逍遥剑客
  • C语言奇淫技巧,字符串的三种表示方法,不会用不是合格的程序员

    char c[12] = {'I','a','m','a','b','o','y','.'};

    诸葛青云

扫码关注云+社区

领取腾讯云代金券