前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python中3个帮助函数help,di

python中3个帮助函数help,di

作者头像
py3study
发布2020-01-06 14:57:33
5790
发布2020-01-06 14:57:33
举报
文章被收录于专栏:python3python3

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

  • 查看模块
代码语言:javascript
复制
>>> 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
  • 查看包
代码语言:javascript
复制
>>> 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::
  • 查看类
代码语言:javascript
复制
>>> 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             |
  • 查看函数:
代码语言:javascript
复制
>>> 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函数:查看变量可用的函数或方法

代码语言:javascript
复制
>>> 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函数:查看变量的类型

代码语言:javascript
复制
<type 'module'>
>>> type (json.__name__)
<type 'str'>
>>> type (json.decoder)
<type 'module'>

4 退出python命令行

windows: ctrl+z 回车

linux:ctrl+d 

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档