You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -371,7 +374,9 @@ Attributes introduced in Python 3.8 and later:
371
374
372
375
Methods
373
376
-------
374
-
### Core Methods
377
+
378
+
**Core Methods**
379
+
375
380
- ``exec(globals_=None, locals_=None)``: Executes the code object within the provided global and local scope dictionaries.
376
381
- ``eval(globals_=None, locals_=None)``: Executes the code object within the provided global and local scope dictionaries and returns the result.
377
382
- ``copy()``: Creates a copy of the `Code` object and returns the duplicate.
@@ -380,19 +385,22 @@ Methods
380
385
- ``get_flags()``: Returns a list of flag names for the ``co_flags`` attribute, e.g., ``["NOFREE"]``.
381
386
- ``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.
382
387
383
-
### Serialization
388
+
**Serialization**
389
+
384
390
- ``to_pycfile(filename)``: Dumps the code object into a `.pyc` file using the ``marshal`` module.
385
391
- ``from_pycfile(filename)``: Creates a `Code` instance from a `.pyc` file.
386
392
- ``from_file(filename)``: Creates a `Code` instance from a `.py` or `.pyc` file.
387
393
- ``pickle(filename)``: Serializes the `Code` object into a pickle file.
388
394
389
-
### Debugging and Inspection
395
+
**Debugging and Inspection**
396
+
390
397
- ``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()``.
391
398
- ``info()``: Internally calls ``dis.show_code`` to display basic information about the bytecode.
392
399
- ``dis(*args, **kw)``: Calls the ``dis`` module to output the disassembly of the bytecode, equivalent to ``dis.dis(c.to_code())``.
393
400
- ``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.)
394
401
395
-
### Factory Functions
402
+
**Factory Functions**
403
+
396
404
- ``fromfunc(function)``: Creates a `Code` instance from a Python function object, equivalent to ``Code(func.__code__)``.
397
405
- ``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.
0 commit comments