neuroradiology / prettytable

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

table.min_width is broken when using PLAIN_COLUMNS style #52

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

import prettytable as pt
x = pt.PrettyTable()
x.add_column('f1', [1,1,1])
x.add_column('f2', [22,22,22])
x.add_column('f3', [333,333,333])
x.min_width['f1'] = 3
x.min_width['f2'] = 3
x.min_width['f3'] = 3
print x.get_string()
x.set_style(pt.PLAIN_COLUMNS)
print x.get_string()

What is the expected output? What do you see instead?

The column with is OK before setting the style but broken after (doubles up).

What version of the product are you using? On what operating system?

Current TRUNK (see attachment), downloaded today and used on 64bit flavors of 
Linux (CentOS and openSUSE).

Please provide any additional information below.

Thanks a lot for this nice piece of software! Would be nice to see the 
min_width function also in an official release!

Best regards!

Original issue reported on code.google.com by danielst...@googlemail.com on 15 May 2014 at 2:35

Attachments:

GoogleCodeExporter commented 8 years ago
Hello Daniel,

I'm a new dev on this project, and I'm looking into this now. It appears that 
setting the style to PLAIN_COLUMNS:

x.set_style(pt.PLAIN_COLUMNS)

sets an internal right_padding_width variable to 8 spaces. That variable is 
what is giving you the extra space in your output. The preset styles are 
supposed to be quick default options, and the right padding width needs to be 
*something* - so 8 characters was chosen "Just as a style thing, man," as my 
old programming professor, Dr. Khabou would say.

If you want to change the padding width to, say, 1 instead of 8 either call

x.right_padding_width = 1

or instead of using set_style, make manual calls to all of the methods called 
therein:

x.header = True
x.border = False
x.padding_width = 1
x.left_padding_width = 0
x.right_padding_width = 1 # <<< this will cure what ails ya

Original comment by john.fil...@gmail.com on 6 Jul 2014 at 9:04

GoogleCodeExporter commented 8 years ago
Hi John,

thanks for looking into this, I'll check and see if this works for me :) I've 
implemented a quality control tool using Python and prettytable for a simple 
report document, and it works nice for now. 

Thanks a lot for that piece of work and best regards,
Daniel

Original comment by danielst...@googlemail.com on 7 Jul 2014 at 3:25