[Tutor] printing columns
Guillermo Fernandez
guillermo.fernandez@epfl.ch
Fri, 26 Jul 2002 10:51:15 +0930
Rob wrote:
>
> Actually, what I had in mind was to have output I could paste directly into
> a C++ header file. The output from my original code should compile without
> error, but I thought it would be a nice touch to display it in pretty
> columns.
I think I get your point (I'm also a maniac of the two columns #define
;-)
Here is a proposed solution. Unfortunately, it only works in cases where
your name plus the #define is less that... 4*number of equivalent spaces
per tabulation.
Each tabulation is equivalent to a number of spaces (is what the
variable of tab_space represents) so you'll have to add plus or less
tabulations depending of how much "equivalent spaces" your #define
ROB_name uses. It's what I try to do in the following program.
If it's not very clear, please told me and I'll try to make it clearer.
menuItems = ['NEW', 'OPEN', 'CLOSE', 'SAVE', 'SAVEAS',
'PAGESETUP', 'PRINTPREVIEW', 'PRINT', 'EXIT',
'UNDO', 'CUT', 'COPY', 'PASTE', 'SEARCH',
'NORMALVIEW', 'PRINTVIEW', 'ZOOMVIEW', 'STANDARDTB',
'EDITTB', 'STATUSTB', 'CUSTOMTB', 'CASCADE', 'TILE',
'SPLIT']
myInt=1
tab_space=8
for item in menuItems:
define='#define ROB_' + item
if len(define) < (2*tab_space):
define+='\t\t\t' + str(myInt)
elif len(define) > (3*tab_space-1):
define+='\t' + str(myInt)
else:
define+='\t\t' + str(myInt)
print define
myInt = myInt + 1
with this we have a two columns output of:
guille/scripts> python test.py
#define ROB_NEW 1
#define ROB_OPEN 2
#define ROB_CLOSE 3
#define ROB_SAVE 4
#define ROB_SAVEAS 5
#define ROB_PAGESETUP 6
#define ROB_PRINTPREVIEW 7
#define ROB_PRINT 8
#define ROB_EXIT 9
#define ROB_UNDO 10
#define ROB_CUT 11
#define ROB_COPY 12
#define ROB_PASTE 13
#define ROB_SEARCH 14
#define ROB_NORMALVIEW 15
#define ROB_PRINTVIEW 16
#define ROB_ZOOMVIEW 17
#define ROB_STANDARDTB 18
#define ROB_EDITTB 19
#define ROB_STATUSTB 20
#define ROB_CUSTOMTB 21
#define ROB_CASCADE 22
#define ROB_TILE 23
#define ROB_SPLIT 24