zestyping / q

Quick and dirty debugging output for tired programmers. ⛺
Apache License 2.0
1.3k stars 62 forks source link

Prevent string and dictionary truncation #59

Open l3ender opened 3 years ago

l3ender commented 3 years ago

I've noticed the following when using q:

Example:

obj = {"my_key": {"aaa": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec et hendrerit ante. Aliquam iaculis magna sed ipsum scelerisque porttitor.", "bbb": "2", "ccc": "3", "ddd": "4", "eee": "5", "fff": "6", "ggg": "7", "hhh": "8", "iii": "9", "jjj": "10", "kkk": "11"}}
q(obj)

# output:
{'my_key': {'aaa': 'Lorem ipsum dolor sit amet, consectetur adipisci...am iaculis magna sed ipsum scelerisque porttitor.', 'bbb': '2', 'ccc': '3', 'ddd': '4', 'eee': '5', 'fff': '6', 'ggg': '7', 'hhh': '8', 'iii': '9', 'jjj': '10', ...}}

Is there a way to prevent it? I'm not very proficient in python so my apologies if this is a simple question. Thanks!!

zestyping commented 3 years ago

Hi! There isn't a friendly way to configure this at the moment, but you could edit q.py to achieve this by altering the maxdict and maxstring attributes, which control the maximum number of dictionary items and maximum number of characters in a string that are shown. You can do this by setting the appropriate attribute just after line 95:

    TEXT_REPR = pydoc.TextRepr()  # this is line 95

    TEXT_REPR.maxdict = 20
    TEXT_REPR.maxstring = 500
l3ender commented 3 years ago

It seems like any changes I make to q.py don't get used when I next run my script. I'm using a virtual environment and editing the file in the virtual env, like:

./venv/lib/python3.9/site-packages/q.py

I've added the TEXT_REPR.maxdict = 20 line, but still don't see the change:

-> python
Python 3.9.1 (default, Dec 10 2020, 10:36:35)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import q
>>> q.TEXT_REPR.maxdict
10

Is there anything else I need to do, or am I editing the wrong file?

rothman857 commented 2 years ago

I think all truncation needs to be disabled by default. This is a wonderful debugging tool, but cutting off debugging data is counterproductive

rothman857 commented 2 years ago

FYI, raised a PR (https://github.com/zestyping/q/pull/60) to address the truncation, assuming this repo is still maintained.

The default truncation levels are far too short for someone debugging.

If the default trunction is still desired, enter: "q.short" in your script.

Long trucation is set by default and can be explitly set by: "q.long"

The truncation can be manuall set by: "q.long = 2000000"