Rid-lin / prettytable

Automatically exported from code.google.com/p/prettytable
Other
0 stars 0 forks source link

Please print empty tables #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We're using PrettyTable in a functional test suite of a web application.
We have a number of tests that parse HTML using xpath, construct a plain Python 
list-of-lists representation, and print it using PrettyTable.

After an upgrade to PrettyTable 0.7.1 we get test failures because empty tables 
(i.e. those that have field names, but no actual rows) no longer get printed.

The old output used to be

    +-----------------+
    | field1 | field2 |
    +-----------------+
    +-----------------+

and if was a perfectly reasonable representation of an empty table, IMHO.

I see some doubt in the new code:

        # Don't think too hard about an empty table
        # Is this the desired behaviour?  Maybe we should still print the header?
        if self.rowcount == 0:
            return ""

so here's my plea to please return the old behaviour back.

Original issue reported on code.google.com by mged...@gmail.com on 29 Mar 2013 at 12:00

GoogleCodeExporter commented 9 years ago
Thanks for reporting that this is causing you problems.

You're right that I was never really sure what the "right" thing to do was in 
this case.  Printing an empty frame *does* seem reasonable.  I'll try to do a 
0.7.2 release tomorrow which either reverts to the old behaviour, or perhaps 
introduces an option which can be used to choose the behaviour for empty 
tables, so that people who have particular needs can set it accordingly.  I'd 
still like to give exactly what to do a little thought...

I'm quite busy IRL at the moment, so there's a chance this might slip of my 
radar - if I haven't done the 0.7.2 release in a couple of days, please feel 
free to comment on this issue and remind me.  I understand you probably want to 
see this fixed ASAP if it's wreaking havoc with your unit tests.

Original comment by luke@maurits.id.au on 1 Apr 2013 at 5:42

GoogleCodeExporter commented 9 years ago
I implemented an ugly workaround for the time being (if no rows, add one, then 
strip it out using str.splitlines()), so there's no need for hurry on my behalf.

Original comment by mged...@gmail.com on 1 Apr 2013 at 7:43

GoogleCodeExporter commented 9 years ago
I have released 0.7.2 today which fixes this problem.

By default, empty tables will now be printed as empty frames as was the old 
behaviour.  But by setting "print_empty" to False, the behaviour of returning 
an empty string can be chosen instead.

Thanks for your patience on this.

Original comment by luke@maurits.id.au on 7 Apr 2013 at 2:19