# Python Bytecode

In the compilation stage, Python first translates source code to a specific **Intermediate Representation (IR)**, and then this IR is converted to machine code. The IR that Python uses is called **Python Bytecode**. The Python Bytecode is stored as `.pyc` file.

When we are given a `.pyc` file, we should try using a Python Bytecode decompiler to get readable source code. For newer versions of Python, use **decompyle3**:

{% embed url="<https://github.com/rocky/python-decompile3>" %}
decompyle3
{% endembed %}

For older versions of Python, use **uncompyle6**:

{% embed url="<https://pypi.org/project/uncompyle6/>" %}
uncompyle6
{% endembed %}

There are some other similar tools for specific Python versions. If the decompiled output does not make sense, always try using other tools.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ret2basic.gitbook.io/ctfnote/reverse/bytecode/python-bytecode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
