Skip to content

Commit f38c526

Browse files
author
qfcy
committed
Update README.rst
1 parent 355ebbc commit f38c526

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

README.rst

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ def __init__(self, code=None)
126126

127127
方法
128128
-------
129-
### 主要方法
129+
130+
**主要方法**
131+
130132
- ``exec(globals_=None, locals_=None)``:在全局和局部作用域字典中执行代码对象。
131133
- ``eval(globals_=None, locals_=None)``:在全局和局部作用域字典中执行代码对象,并获取返回值。
132134
- ``copy()``:复制一份``Code``对象,返回复制的副本。
@@ -135,20 +137,21 @@ def __init__(self, code=None)
135137
- ``get_flags()``:返回 ``co_flags`` 属性的标志名称列表,如``["NOFREE"]``。
136138
- ``get_sub_code(name)``:搜索代码的``co_consts``中的子代码,如函数、类定义等,不会递归搜索。返回搜索到的``Code``对象,未找到时抛出``ValueError``。
137139

138-
### 序列化
140+
**序列化**
141+
139142
- ``to_pycfile(filename)``:使用 ``marshal`` 模块将代码对象转储到 ``.pyc`` 文件中。
140143
- ``from_pycfile(filename)``:从 ``.pyc`` 文件创建 ``Code`` 实例。
141144
- ``from_file(filename)``:从 ``.py`` 或 ``.pyc`` 文件创建 ``Code`` 实例。
142145
- ``pickle(filename)``:将 ``Code`` 对象序列化为 pickle 文件。
143146

144-
### 调试和检查
147+
**调试和检查**
145148

146149
- ``show(*args, **kw)``:在内部调用``pyobject.desc``,显示代码对象的属性,参数用法和``desc()``的用法相同。
147150
- ``info()``:在内部调用``dis.show_code``,显示字节码的基本信息。
148151
- ``dis(*args, **kw)``:调用 ``dis`` 模块输出字节码的反汇编,和``dis.dis(c.to_code())``相同。
149152
- ``decompile(version=None, *args, **kw)``:调用 ``uncompyle6`` 库将代码对象反编译为源代码。(安装``pyobject``库时, ``uncompyle6`` 库是可选的。)
150153

151-
### 工厂函数
154+
**工厂函数**
152155

153156
- ``fromfunc(function)``:从 Python 函数对象创建 ``Code`` 实例,和``Code(func.__code__)``相同。
154157
- ``fromstring(string, mode='exec', filename='')``:从源代码字符串创建 ``Code`` 实例,参数用法和``compile``内置函数相同,在内部调用``compile()``。
@@ -371,7 +374,9 @@ Attributes introduced in Python 3.8 and later:
371374

372375
Methods
373376
-------
374-
### Core Methods
377+
378+
**Core Methods**
379+
375380
- ``exec(globals_=None, locals_=None)``: Executes the code object within the provided global and local scope dictionaries.
376381
- ``eval(globals_=None, locals_=None)``: Executes the code object within the provided global and local scope dictionaries and returns the result.
377382
- ``copy()``: Creates a copy of the `Code` object and returns the duplicate.
@@ -380,19 +385,22 @@ Methods
380385
- ``get_flags()``: Returns a list of flag names for the ``co_flags`` attribute, e.g., ``["NOFREE"]``.
381386
- ``get_sub_code(name)``: Searches for sub-code objects (e.g., functions or class definitions) in the ``co_consts`` attribute. This method does not perform recursive searches. Returns the found `Code` object or raises a ``ValueError`` if not found.
382387

383-
### Serialization
388+
**Serialization**
389+
384390
- ``to_pycfile(filename)``: Dumps the code object into a `.pyc` file using the ``marshal`` module.
385391
- ``from_pycfile(filename)``: Creates a `Code` instance from a `.pyc` file.
386392
- ``from_file(filename)``: Creates a `Code` instance from a `.py` or `.pyc` file.
387393
- ``pickle(filename)``: Serializes the `Code` object into a pickle file.
388394

389-
### Debugging and Inspection
395+
**Debugging and Inspection**
396+
390397
- ``show(*args, **kw)``: Internally calls ``pyobject.desc`` to display the attributes of the code object. The parameters are the same as those used in ``desc()``.
391398
- ``info()``: Internally calls ``dis.show_code`` to display basic information about the bytecode.
392399
- ``dis(*args, **kw)``: Calls the ``dis`` module to output the disassembly of the bytecode, equivalent to ``dis.dis(c.to_code())``.
393400
- ``decompile(version=None, *args, **kw)``: Calls the ``uncompyle6`` library to decompile the code object into source code. (The ``uncompyle6`` library is optional when installing the ``pyobject`` package.)
394401

395-
### Factory Functions
402+
**Factory Functions**
403+
396404
- ``fromfunc(function)``: Creates a `Code` instance from a Python function object, equivalent to ``Code(func.__code__)``.
397405
- ``fromstring(string, mode='exec', filename='')``: Creates a `Code` instance from a source code string. The parameters are the same as those used in the built-in ``compile`` function, which is called internally.
398406

0 commit comments

Comments
 (0)