Skip to main content

prina: print python variable with the variable name.

🦥 打印 Python 变量时,带着变量名称。

缘起

不知道你有没有这样的烦恼,在没有 IDE 的情况下做调试时,都会写一堆打印信息来查看数据是否准确。

比如:

a = "1"
b = 2
c = True
print(a, b, c)
# 1 2 True

如果直接这样打印,在控制台的输出中就很难区分不同变量的值。

因此需要安装下面的方式来书写,其中就有很多变量名需要写两遍。

a = "1"
b = 2
c = True
print("a: {} b: {} c: {}".format(a, b, c))
# or (Python3.6+ 支持的语法)
print(f"a: {a} b: {b} c: {c}")
# a: 1 b: 2 c: True

那么有没有一种方法可以打印 Python 变量时,带着变量名称呢?

我找了半天 Python 的内置函数,发现都无法完成这一功能,于是就有了 prina 这个库。

prina = print + name

使用方法

from prina import prina

a = "1"
b = 2
c = True

prina(a, b, c)
# a: 1 b: 2 c: True

其他

在 Python 3.8 中,你可以使用 f-string 来调试文档:

a = "1"
b = 2
c = True

print(f"{a=} {b=} {c=}")
# a=1 b=2 c=True

许可

Metadata

Release files for prina 0.1.3

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

Source distribution (sdist)

Source distribution for prina 0.1.3
File Size Uploaded Provenance Actions
prina-0.1.3.tar.gz 3.4 kB Without provenance Details for prina-0.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 7.4 kB

Release files / prina-0.1.3.tar.gz

Download URL prina-0.1.3.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f5d4486bc9655c715d5508780d423a73b43148adfaae3e9e71a9fa2b3356b949
BLAKE2b-256 checksum
How to use checksums
baca7782b9e0ab50abc1827d25e3da2ccde1c348d3cc55a68c69c855d0f807af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / prina-0.1.3-py3-none-any.whl

Download URL prina-0.1.3-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6327496c23116679243ef6a4251dcf6a651cfa7c79ff0863674b0bdf910588d2
BLAKE2b-256 checksum
How to use checksums
b61cf124e66a6881548246356e610a309ab43581824bbe95f71b6386db1da3f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Security for prina 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files No provenance

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