Skip to main content

About linetable

https://github.com/amol-/linetable/actions/workflows/run-tests.yml/badge.svg https://coveralls.io/repos/amol-/linetable/badge.svg https://img.shields.io/pypi/v/linetable.svg https://img.shields.io/pypi/pyversions/linetable.svg https://img.shields.io/pypi/l/linetable.svg

linetable is a library parse and generate co_linetable attributes in Python code objects.

Based on https://github.com/python/cpython/blob/main/Objects/locations.md

Installing

linetable can be installed from pypi:

pip install linetable

should just work for most of the users

Usage

Existing linetable can be parsed using linetable.parse_linetable:

>>> def testfunc():
...   x = 3
...   y = x + 1
...   return y

>>> list(linetable.parse_linetable(testfunc.__code__.co_linetable))
[
    (1, 1, 1, 0, 0),
    (1, 2, 2, 6, 7),
    (1, 2, 2, 2, 3),
    (1, 3, 3, 6, 7),
    (1, 3, 3, 10, 11),
    (2, 3, 3, 6, 11),
    (1, 3, 3, 2, 3),
    (1, 4, 4, 9, 10),
    (1, 4, 4, 2, 10),
]

If you prefer the output in the format of dis.Positions objects, you can create them from the yielded values:

>>> [dis.Positions(*e[1:]) for e in linetable.parse_linetable(testfunc.__code__.co_linetable)]
[Positions(lineno=1, end_lineno=1, col_offset=0, end_col_offset=0), Positions(lineno=2, end_lineno=2, col_offset=8, end_col_offset=9), Positions(lineno=2, end_lineno=2, col_offset=4, end_col_offset=5), Positions(lineno=3, end_lineno=3, col_offset=8, end_col_offset=9), Positions(lineno=3, end_lineno=3, col_offset=12, end_col_offset=13), Positions(lineno=3, end_lineno=3, col_offset=8, end_col_offset=13), Positions(lineno=3, end_lineno=3, col_offset=4, end_col_offset=5), Positions(lineno=4, end_lineno=4, col_offset=11, end_col_offset=12), Positions(lineno=4, end_lineno=4, col_offset=4, end_col_offset=12)]

If you have the linetable, you can generate back the binary encoded version using linetable.generate_linetable:

>>> lt = [
...     (1, 1, 1, 0, 0),
...     (1, 2, 2, 6, 7),
...     (1, 2, 2, 2, 3),
...     (1, 3, 3, 6, 7),
...     (1, 3, 3, 10, 11),
...     (2, 3, 3, 6, 11),
...     (1, 3, 3, 2, 3),
...     (1, 4, 4, 9, 10),
...     (1, 4, 4, 2, 10),
... ]
>>> linetable.generate_linetable(lt)
b"\x80\x00\xd8\x06\x07\x80!\xd8\x06\x07\x88!\x81e\x80!\xd8\t\n\x80("

Metadata

Release files for linetable 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for linetable 0.0.4
File Size Uploaded
linetable-0.0.4.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for linetable 0.0.4
File Interpreter ABI Platform
linetable-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 9.6 kB

Release files / linetable-0.0.4.tar.gz

Download URL linetable-0.0.4.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a6f866a84183a206acf0d53d4a2529dde18a13bca4db99cb4374d6c2ece82ade
BLAKE2b-256 checksum
How to use checksums
76c48ab9a5eba14bf9006ad6e966a2ea47a9d6b3b3da913710dc5c2ee2f447d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / linetable-0.0.4-py3-none-any.whl

Download URL linetable-0.0.4-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba446b0b268b313c97542e10916aa6f0d4f56beb4878e8ee2a6430790dee92d7
BLAKE2b-256 checksum
How to use checksums
c755eaa270a33bc9fdd22c16b590fa8f552793c8b59aee3059c1ef5fd88df7d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page