Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent string and dictionary truncation #59

Open
l3ender opened this issue May 22, 2021 · 4 comments
Open

Prevent string and dictionary truncation #59

l3ender opened this issue May 22, 2021 · 4 comments

Comments

@l3ender
Copy link

l3ender commented May 22, 2021

I've noticed the following when using q:

  • long strings are abbreviated with ... in the middle.
  • dictionary objects with greater than 10 entries print the first 10 and then truncate the rest using ....

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!!

@l3ender l3ender changed the title Prevent dictionary truncation Prevent string and dictionary truncation May 22, 2021
@zestyping
Copy link
Owner

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
Copy link
Author

l3ender commented Jun 23, 2021

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
Copy link
Contributor

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

@rothman857
Copy link
Contributor

FYI, raised a PR (#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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants