gaogaotiantian / objprint

A library that can print Python objects in human readable format
Apache License 2.0
519 stars 43 forks source link

[Feature Request] Limit number of rows displayed for large arrays/dictionaries #88

Closed happytree718 closed 1 year ago

happytree718 commented 1 year ago

Hello,

I hope you're doing well. I would like to propose a feature enhancement that I believe could improve the user experience when dealing with large arrays or dictionaries. Currently, when using objprint to print an object with a large array or dictionary, it displays all the elements, making the output lengthy and overwhelming.

It would be great to have an optional argument that allows us to limit the number of rows displayed for arrays or dictionaries, similar to how pandas handles DataFrame display. By default, pandas shows 5 rows at the beginning and 5 at the end, with an ellipsis (…) in between to indicate that more rows are not shown. This approach gives users an idea of what's inside the data structure without cluttering the terminal output.

For instance, consider the following example:

from objprint import op, install

class Sample:
    def __init__(self, dict) -> None:
        self.data = dict

test_dict = {i:i for i in range(100)}

_ = op(Sample(test_dict))

In this case, objprint would print all 100 key-value pairs in self.data, making the output very long. It would be beneficial to have an option to display only the first and last few lines of the dictionary.

If you think this feature would be a valuable addition to the library, I would be more than happy to contribute to its implementation. Please let me know your thoughts on this suggestion.

Thank you for your time and consideration! Looking forward to hearing from you.

Best Regards, Erwin

gaogaotiantian commented 1 year ago

_ = op(Sample(test_dict), elements=10)?

happytree718 commented 1 year ago

Yes, or as a global config if the user wants to use the same element setup in the same file.

gaogaotiantian commented 1 year ago

Yes, or as a global config if the user wants to use the same element setup in the same file.

I meant - try _ = op(Sample(test_dict), elements=10)

gaogaotiantian commented 1 year ago

Or op.config(elements=10)