SkillAgentSearch skills...

Pymg

pymg is a CLI that can interpret Python files by the Python interpreter and display the error message in a more readable way if an exception occurs.

Install / Use

/learn @mimseyedi/Pymg
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

pypi support-version license commit

img1

Table of Contents: <a class="anchor" id="contents"></a>

Introduction <a class="anchor" id="intro"></a>

pymg is a CLI tool that can interpret Python files by the Python interpreter and display the error message in a more readable way if an exception occurs.

Installation <a class="anchor" id="install"></a>

You can use pip to install:

python3 -m pip install pymg

And also to upgrade:

python3 -m pip install --upgrade pymg

<a class="anchor" id="usage"></a>

img1

Using the --help option <a class="anchor" id="help"></a>

With the help of the (-h, --help) option, you can easily see how to use pymg and the explanations of the options.

Usage: pymg [OPTIONS] [PYTHON_FILE]...

  pymg is a CLI tool that can interpret Python files by the Python interpreter
  and display the error message in a more readable way if an exception occurs.

Options:
  -x, --syntax       It checks the syntax of the selected Python file. If
                     there is a syntax problem, an error message will be
                     displayed, otherwise 'INTACT' will be displayed.
  -t, --type         The type of exception that occurred will be displayed.
  -m, --message      The message of exception that occurred will be displayed.
  -f, --file         The full path of the Python file where the exception
                     occurred will be displayed.
  -s, --scope        The scope where the exception occurred will be displayed.
  -l, --line         The line number that caused the exception will be
                     displayed.
  -c, --code         The code that caused the exception will be displayed.
  -T, --trace        All paths that contributed to the creation of the
                     exception will be tracked, and then, with separation,
                     each created stack will be displayed.
  -i, --inner        Just like the --trace option, The exception that occurred
                     will be tracked and the result will be limited and
                     displayed to the internal content of the selected Python
                     file.
  -L, --locals       The last value of each scope's local variables before the
                     exception occurs will be displayed. This option can be
                     combined with --trace and --inner.
  -S, --search       With the help of stackoverflow api, the links of answered
                     posts related to the exception that occurred will be
                     displayed.
  -o, --output PATH  Writes the output to a text file. It has an argument that
                     contains the path of the text file.
  -r, --recent       Redisplays the last operation performed.
  -v, --version      Displays the current version of pymg installed on the
                     system.
  -h, --help         Show this message and exit.

Interpret the file without options <a class="anchor" id="no_option"></a>

By default, (-i, --inner) and (-L, --locals) will happen if you don't select any options. Combining these two options will make an effective form of error message.

Let's check the test.py file as an example:

import sys

def div(a, b):
    return a / b

print(div(int(sys.argv[1]), int(sys.argv[2])))

The task of this program is very simple. It passes the two values it receives from the command line arguments to the div function, and the div function divides them.

Now let us interpret the test.py file with pymg so that the ZeroDivisionError exception occurs.

pymg test.py 4 0

Output: img1

Syntax validation using the --syntax option <a class="anchor" id="syntax"></a>

Let's create an intentional syntax problem in the test.py file:

import sys

def div(a, b):
    return (a / b

print(div(int(sys.argv[1]), int(sys.argv[2])))

Now we will use the (-x, --syntax) option:

pymg test.py 4 0 -x

Output: img1

SyntaxError always precedes exceptions, and even if you don't use the (-x, --syntax) option, it will be checked at interpret time.

Pay attention to the following command, which displays a similar output:

pymg test.py 4 0

Output: img1

IndentationError and TabError will also be checked in the syntax checking stage:

import sys

def div(a, b):
return a / b

print(div(int(sys.argv[1]), int(sys.argv[2])))

Output: img1

Combination of options <a class="anchor" id="combine"></a>

pymg allows you to combine options to access all the features of the exception separately and get different outputs:

pymg test.py 4 0 -f -s -l -c -m

Output: img1

But some options are ahead of others, you can see the prioritization of options <a href="https://github.com/mimseyedi/pymg/blob/master/docs/guide/how_does_pymg_work.md#pri_options">here</a>.

For example, using the (-T, --trace) option, other options will not work (Because all the options are included in this option):

pymg test.py 4 0 -f -s -l -c -m -T

Output: img1

Combination of --trace and --inner options with --locals <a class="anchor" id="T_i_L"></a>

The (-T, --trace) and (-i, --inner) options can be combined with (-L, --locals) option:

pymg test.py -i -L

Output: img1

Using the --recent option <a class="anchor" id="recent"></a>

By using the --recent option, you can re-execute the last operation you have done. pymg saves your last move.

Search for a solution with the --search option <a class="anchor" id="search"></a>

You can search for solutions to your problems in stackoverflow by using the (-S, --search) option. pymg searches stackoverflow for the exception and shows you the title and link of the posts that got the answer:

pymg test.py 4 0 -S

Output: img1

Write the output to the file with the --output option <a class="anchor" id="syntax"></a>

You can use the (-o, --output) option to write the generated output in a text file:

pymg test.py -T -L -o output.txt

output.txt

╭─────────────────────────────────────────── Exception ───────────────────────────────────────────╮
│ Exception Type ❱ JSONDecodeError                                                                │
│ Exception Message ❱ Expecting value: line 1 column 1 (char 0)                                   │
│                                                                                                 │
│ ╭─ Trace[1] - <module> ───────────────────────────────────────────────────────────────────────╮ │
│ │                                                                                             │ │
│ │ File: /Users/mimseyedi/Desktop/test.py                                                      │ │
│ │                                                                                             │ │
│ │ ❱ 8 print(read_json_file(json_file_path))                                                   │ │
│ │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                    │ │
│ │                                                                                             │ │
│ │ ╭───────────────────────── locals ──────────────────────────╮                               │ │
│ │ │ read_json_file = <function read_json_file at 0x1012705e0> │                               │ │
│ │ │ json_file_path = json_file.json                           │                               │ │
│ │ ╰───────────────────────────────────────────────────────────╯                               │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                 │
│ ╭─ Trace[2] - read_json_file ─────────────────────────────────────────────────────────────────╮ │
│ │                          

Related Skills

View on GitHub
GitHub Stars87
CategoryDevelopment
Updated8mo ago
Forks4

Languages

Python

Security Score

92/100

Audited on Jul 29, 2025

No findings