Open GoogleCodeExporter opened 9 years ago
If you were using github or git I'd submit a PR; but since you're using SVN
I've attached an updated copy of the prettytable.py. This version does two
things:
1. Enables my use case above by introducing a new function - print_table() -
that prints the lines to a file (default sys.stdout) instead of building them
into a list.
Instead of:
print(myprettytable)
You do:
myprettytable.print_table()
It also takes a file and end parameter like the print() does so callers can
redirect as desired.
2. Reduces memory significantly by using a generator - my test went from
11-12GB of RAM down to just under 7 GB of RAM usage.
The original get_string() was split into a few more functions to re-use the
code between the get_string() and print_table().
While this version works, and does a great job for the really big tables; it
could be further improved if the formatted data did not have to be saved.
prettytable_alternate.py is an attempt to use more generators to reduce memory.
Indeed it did work - peak was down to just over 5GB, and normal was around
4.7GB - but it also took a lot longer to output the data (it also had to format
the data twice due to the row generator). However, in both cases data is being
outputted earlier than the original implementation since it can be outputted
before all the data is completely built up.
Perhaps you have other ideas on how to speed this all up and reduce memory
consumption for the very large table variants.
Original comment by gpcl...@gmail.com
on 15 Dec 2014 at 11:35
Attachments:
Original issue reported on code.google.com by
gpcl...@gmail.com
on 15 Dec 2014 at 5:02