prettytable 0.5__tar.gz → 0.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ ########## PrettyTable 0.6.1 - June 03, 2012 ##########
2
+
3
+ * Unicode encoding scheme can now be set by user
4
+ * __str__ now uses user-specified encoding instead of ASCII. This
5
+ fixes a bug where tables with non-ASCII characters would print
6
+ correctly with "print x.get_string()" but not "print x" in 2.x
7
+ (thanks to Google Code user kevincobain2000 for reporting this
8
+ bug!)
9
+ * Fixed an incompatibility with 3.0 and 3.1 (html.escape was new
10
+ in 3.2)
11
+
12
+ ########## PrettyTable 0.6 - April 05, 2012 ##########
13
+
14
+ * Code is now simultaneously compatible with Python 2 and 3
15
+ * Replaced all setter methods with managed attributes
16
+ * All styling options can now be set persistently as managed attributes
17
+ * Added "add_style" method to make setting style options easily
18
+ * Added "del_row", "clear_rows" and "clear" methods to facilitate
19
+ removal of data from table.
20
+ * Added "copy" method to facilitate cloning of a table.
21
+ * Removed caching functionality, which added complexity and fragility
22
+ for relatively little gain
23
+ * Removed methods that just printed strings produced by get_string and
24
+ get_html_string - just use inbuilt print!
25
+ * Improved unicode support (thanks to Google Code user ru.w31rd0 for
26
+ patch!)
27
+ * Added support for decimal and floating point number formatting
28
+ support (thanks to Google Code user willfurnass for the suggestion!)
29
+ * Added support for using a custom key sorting methods (thanks to
30
+ Google Code user amannijhawan for the suggestion!)
31
+ * Added support for line breaks in data (suggested and implemented by
32
+ Klein Stephane)
33
+ * Added support for max column widths (thanks to Tibor Arpas for the
34
+ suggestion!)
35
+ * Fixed table slicing
36
+ * Fixed bug where closing <tr/> tags in HTML tables were not printed
37
+ (thanks to Google Code user kehander for reporting this bug!)
38
+ * Fixed HTML table sorting bug (thanks to Google Code user dougbeal
39
+ for reporting this bug!)
40
+ * Fixed bug whereby changing field_names did not recompute widths
41
+ (thanks to Google Code user denilsonsa for reporting this bug!)
42
+
43
+ ########## PrettyTable 0.5 - May 26, 2009 ##########
44
+
45
+ * Fixed a bug whereby printing with headers=False and border=False
46
+ would introduce an extraneous newline. Thanks to Alexander Lamaison
47
+ for reporting this bug.
48
+ * When printing with headers=False, column widths will now be reduced
49
+ as appropriate in columns where the field name is wider than the
50
+ data. Thanks to Alexander Lamaison for suggesting this behaviour.
51
+ * Support for Unicode has improved. Thanks to Chris Clark for
52
+ submitting this improvement.
53
+ * The value of the "border" argument now correctly controls the
54
+ presence of a border when printing HTML tables with print_html or
55
+ get_html_string, instead of being incorrectly ignored. Thanks to
56
+ Chris Clark for fixing this.
57
+ * The print_html and get_html_string methods now accept an
58
+ "attributes" argument which is a dictionary of name/value pairs to be
59
+ placed inside the <table> tag (so you can, e.g. set class, name or id
60
+ values in order to style your table with CSS). Thanks to Chris Clark
61
+ for submitting this feature.
62
+ * The print_html and get_html_string methods now, by default, do their
63
+ best to match the various formatting options in their HTML output.
64
+ They use inline CSS to adjust the alignment of data in columns, the
65
+ padding widths of columns and in some cases the border settings. You
66
+ can give either method a "format=False" attribute to turn this
67
+ behaviour off if you want to do your own styling. With "format=False"
68
+ the methods print a "bare bones" table, similar to the default
69
+ behaviour in 0.4.
70
+
71
+ ########## PrettyTable 0.4 - May 13, 2009 ##########
72
+
73
+ * Added "add_column" method to enable building tables up column-by-column.
74
+ * Added "print_HTML" and "get_HTML_string" methods to enable HTML table
75
+ production.
76
+ * Added "set_border_chars" method to enable control over characters used to
77
+ draw the table border.
78
+ * Added "set_left_padding" and "set_right_padding" methods to allow
79
+ independent padding control for both sides of a column.
80
+ * Added "sortby" option to enable column sorting.
81
+ * Added "header" option to enable switching off field name printing at top of
82
+ table.
83
+ * Modified "hrules" option to enable greater control over presence of
84
+ horizontal lines.
85
+ * Added "border" option to enable switching off all line printing.
86
+
87
+ Thanks to Tim Cera, Chris Clark, Alexander Lamaison for suggesting and helping
88
+ to test many of the new features in this release.
89
+
90
+ ########## PrettyTable 0.3 - May 01, 2009 ##########
91
+
92
+ * Added "padding_width" option to control the number of spaces between the
93
+ vertical line rules at the edges of a column and its content. This can be
94
+ set as a keyword argument to the constructor or after instantiation using
95
+ the "set_padding_width" method. The value is set to 1 by defaut. If your
96
+ table is too wide for a small screen with this value, setting it to 0 might
97
+ help you squeeze it in.
98
+
99
+ Thanks to Chris Clark for contributing a patch against 0.2.1 to add this
100
+ feature!
101
+
102
+ ########## PrettyTable 0.2.1 - April 29, 2009 ##########
103
+
104
+ * Caching no longer breaks when using the "printt(fields=[...])" syntax. The
105
+ list of fields was not hashable and hence could not be used as a dictionary
106
+ key. I fixed this using the output of the "cPickle" module's "dumps"
107
+ function as the dictionary key instead.
108
+ * Horizontal lines are now the appropriate length when the above syntax is
109
+ used.
110
+
111
+ Thanks to Julien Koesten for reporting these bugs and testing the fixes almost
112
+ immediately after the release of 0.2!
113
+
114
+ ########## PrettyTable 0.2 - April 29, 2009 ##########
115
+
116
+ * Added "get_string" method.
117
+ * Added "__str__" method (which just calls "get_string") to enable nice
118
+ "print x" syntax.
119
+ * Can now pass field names as a constructor argument.
120
+ * Return values of "get_string" are cached in a dictionary that is only
121
+ cleared after a call to "add_row" or something else which invalidates the
122
+ cache.
123
+
124
+ ########## PrettyTable 0.1 - February 26, 2009 #########
125
+
126
+ * Original release
@@ -0,0 +1,28 @@
1
+ # Copyright (c) 2009-2012 Luke Maurits <luke@maurits.id.au>
2
+ # All rights reserved.
3
+ # With contributions from:
4
+ # * Chris Clark
5
+ # * Klein Stephane
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions are met:
9
+ #
10
+ # * Redistributions of source code must retain the above copyright notice,
11
+ # this list of conditions and the following disclaimer.
12
+ # * Redistributions in binary form must reproduce the above copyright notice,
13
+ # this list of conditions and the following disclaimer in the documentation
14
+ # and/or other materials provided with the distribution.
15
+ # * The name of the author may not be used to endorse or promote products
16
+ # derived from this software without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ # POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,4 @@
1
+ include COPYING
2
+ include CHANGELOG
3
+ include README
4
+ include prettytable_test.py
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 1.0
2
+ Name: prettytable
3
+ Version: 0.6.1
4
+ Summary: A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
5
+ Home-page: http://code.google.com/p/prettytable
6
+ Author: Luke Maurits
7
+ Author-email: luke@maurits.id.au
8
+ License: BSD (3 clause)
9
+ Description: UNKNOWN
10
+ Platform: UNKNOWN
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 2.6
13
+ Classifier: Programming Language :: Python :: 2.7
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: License :: OSI Approved :: BSD License
16
+ Classifier: Topic :: Text Processing
@@ -0,0 +1,462 @@
1
+ TUTORIAL ON HOW TO USE THE PRETTYTABLE 0.6 API
2
+
3
+ *** This tutorial is distributed with PrettyTable and is meant to serve
4
+ as a "quick start" guide for the lazy or impatient. It is not an
5
+ exhaustive description of the whole API, and it is not guaranteed to be
6
+ 100% up to date. For more complete and update documentation, check the
7
+ PrettyTable wiki at http://code.google.com/p/prettytable/w/list ***
8
+
9
+ = Getting your data into (and out of) the table =
10
+
11
+ Let's suppose you have a shiny new PrettyTable:
12
+
13
+ from prettytable import PrettyTable
14
+ x = PrettyTable()
15
+
16
+ and you want to put some data into it. You have two (sane) options
17
+
18
+ == Row by row ==
19
+
20
+ You can add data one row at a time. To do this you need to set the field names
21
+ first using the `set_field_names` method, and then add the rows one at a time
22
+ using the `add_row` method:
23
+
24
+ x.set_field_names(["City name", "Area", "Population", "Annual Rainfall"])
25
+ x.add_row(["Adelaide",1295, 1158259, 600.5])
26
+ x.add_row(["Brisbane",5905, 1857594, 1146.4])
27
+ x.add_row(["Darwin", 112, 120900, 1714.7])
28
+ x.add_row(["Hobart", 1357, 205556, 619.5])
29
+ x.add_row(["Sydney", 2058, 4336374, 1214.8])
30
+ x.add_row(["Melbourne", 1566, 3806092, 646.9])
31
+ x.add_row(["Perth", 5386, 1554769, 869.4])
32
+
33
+ == Column by column ==
34
+
35
+ You can add data one column at a time as well. To do this you use the
36
+ `add_column` method, which takes two arguments - a string which is the name for
37
+ the field the column you are adding corresponds to, and a list or tuple which
38
+ contains the column data"
39
+
40
+ x.add_column("City name",
41
+ ["Adelaide","Brisbane","Darwin","Hobart","Sydney","Melbourne","Perth"])
42
+ x.add_column("Area", [1295, 5905, 112, 1357, 2058, 1566, 5386])
43
+ x.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092,
44
+ 1554769])
45
+ x.add_column("Annual Rainfall",[600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9,
46
+ 869.4])
47
+
48
+ == Mixing and matching ==
49
+
50
+ If you really want to, you can even mix and match `add_row` and `add_column`
51
+ and build some of your table in one way and some of it in the other. There's a
52
+ unit test which makes sure that doing things this way will always work out
53
+ nicely as if you'd done it using just one of the two approaches. Tables built
54
+ this way are kind of confusing for other people to read, though, so don't do
55
+ this unless you have a good reason.
56
+
57
+ == Getting data out ==
58
+
59
+ There are three ways to get data out of a PrettyTable, in increasing order of
60
+ completeness:
61
+
62
+ * The `del_row` method takes an integer index of a single row to delete.
63
+ * The `clear_rows` method takes no arguments and deletes all the rows in the
64
+ table - but keeps the field names as they were so you that you can repopulate
65
+ it with the same kind of data.
66
+ * The `clear` method takes no arguments and deletes all rows and all field
67
+ names. It's not quite the same as creating a fresh table instance, though -
68
+ style related settings, discussed later, are maintained.
69
+
70
+ = Displaying your table in ASCII form =
71
+
72
+ PrettyTable's main goal is to let you print tables in an attractive ASCII form,
73
+ like this:
74
+
75
+ +-----------+------+------------+-----------------+
76
+ | City name | Area | Population | Annual Rainfall |
77
+ +-----------+------+------------+-----------------+
78
+ | Adelaide | 1295 | 1158259 | 600.5 |
79
+ | Brisbane | 5905 | 1857594 | 1146.4 |
80
+ | Darwin | 112 | 120900 | 1714.7 |
81
+ | Hobart | 1357 | 205556 | 619.5 |
82
+ | Melbourne | 1566 | 3806092 | 646.9 |
83
+ | Perth | 5386 | 1554769 | 869.4 |
84
+ | Sydney | 2058 | 4336374 | 1214.8 |
85
+ +-----------+------+------------+-----------------+
86
+
87
+ You can print tables like this to `stdout` or get string representations of
88
+ them.
89
+
90
+ == Printing ==
91
+
92
+ To print a table in ASCII form, you can just do this:
93
+
94
+ print x
95
+
96
+ in Python 2.x or:
97
+
98
+ print(x)
99
+
100
+ in Python 3.x.
101
+
102
+ The old x.printt() method from versions 0.5 and earlier has been removed. To
103
+ pass options changing the look of the table, use the get_string() method
104
+ documented below:
105
+
106
+ print x.get_string()
107
+
108
+ == Stringing ==
109
+
110
+ If you don't want to actually print your table in ASCII form but just get a
111
+ string containing what _would_ be printed if you use "print x", you can use
112
+ the `get_string` method:
113
+
114
+ mystring = x.get_string()
115
+
116
+ This string is guaranteed to look exactly the same as what would be printed by
117
+ doing "print x". You can now do all the usual things you can do with a
118
+ string, like write your table to a file or insert it into a GUI.
119
+
120
+ == Controlling which data gets displayed ==
121
+
122
+ If you like, you can restrict the output of `print x` or `x.get_string` to
123
+ only the fields or rows you like.
124
+
125
+ The `fields` argument to these methods takes a list of field names to be
126
+ printed:
127
+
128
+ print x.get_string(fields=["City name", "Population"])
129
+
130
+ gives:
131
+
132
+ +-----------+------------+
133
+ | City name | Population |
134
+ +-----------+------------+
135
+ | Adelaide | 1158259 |
136
+ | Brisbane | 1857594 |
137
+ | Darwin | 120900 |
138
+ | Hobart | 205556 |
139
+ | Melbourne | 3806092 |
140
+ | Perth | 1554769 |
141
+ | Sydney | 4336374 |
142
+ +-----------+------------+
143
+
144
+ The `start` and `end` arguments take the index of the first and last row to
145
+ print respectively. Note that the indexing works like Python list slicing - to
146
+ print the 2nd, 3rd and 4th rows of the table, set `start` to 1 (the first row
147
+ is row 0, so the second is row 1) and set `end` to 4 (the index of the 4th row,
148
+ plus 1):
149
+
150
+ print x.get_string(start=1,end=4)
151
+
152
+ prints:
153
+
154
+ +-----------+------+------------+-----------------+
155
+ | City name | Area | Population | Annual Rainfall |
156
+ +-----------+------+------------+-----------------+
157
+ | Brisbane | 5905 | 1857594 | 1146.4 |
158
+ | Darwin | 112 | 120900 | 1714.7 |
159
+ | Hobart | 1357 | 205556 | 619.5 |
160
+ +-----------+------+------------+-----------------+
161
+
162
+ == Changing the alignment of columns ==
163
+
164
+ By default, all columns in a table are centre aligned.
165
+
166
+ === All columns at once ===
167
+
168
+ You can change the alignment of all the columns in a table at once by assigning
169
+ a one character string to the `align` attribute. The allowed strings are "l",
170
+ "r" and "c" for left, right and centre alignment, respectively:
171
+
172
+ x.align = "r"
173
+ print x
174
+
175
+ gives:
176
+
177
+ +-----------+------+------------+-----------------+
178
+ | City name | Area | Population | Annual Rainfall |
179
+ +-----------+------+------------+-----------------+
180
+ | Adelaide | 1295 | 1158259 | 600.5 |
181
+ | Brisbane | 5905 | 1857594 | 1146.4 |
182
+ | Darwin | 112 | 120900 | 1714.7 |
183
+ | Hobart | 1357 | 205556 | 619.5 |
184
+ | Melbourne | 1566 | 3806092 | 646.9 |
185
+ | Perth | 5386 | 1554769 | 869.4 |
186
+ | Sydney | 2058 | 4336374 | 1214.8 |
187
+ +-----------+------+------------+-----------------+
188
+
189
+ === One column at a time ===
190
+
191
+ You can also change the alignment of individual columns based on the
192
+ corresponding field name by treating the `align` attribute as if it were a
193
+ dictionary.
194
+
195
+ x.align["City name"] = "l"
196
+ x.align["Area"] = "c"
197
+ x.align["Population"] = "r"
198
+ x.align["Annual Rainfall"] = "c"
199
+ print x
200
+
201
+ gives:
202
+
203
+ +-----------+------+------------+-----------------+
204
+ | City name | Area | Population | Annual Rainfall |
205
+ +-----------+------+------------+-----------------+
206
+ | Adelaide | 1295 | 1158259 | 600.5 |
207
+ | Brisbane | 5905 | 1857594 | 1146.4 |
208
+ | Darwin | 112 | 120900 | 1714.7 |
209
+ | Hobart | 1357 | 205556 | 619.5 |
210
+ | Melbourne | 1566 | 3806092 | 646.9 |
211
+ | Perth | 5386 | 1554769 | 869.4 |
212
+ | Sydney | 2058 | 4336374 | 1214.8 |
213
+ +-----------+------+------------+-----------------+
214
+
215
+ == Sorting your table by a field ==
216
+
217
+ You can make sure that your ASCII tables are produced with the data sorted by
218
+ one particular field by giving `get_string` a `sortby` keyword argument, which
219
+ must be a string containing the name of one field.
220
+
221
+ For example, to print the example table we built earlier of Australian capital
222
+ city data, so that the most populated city comes last, we can do this:
223
+
224
+ print x.get_string(sortby="Population")
225
+
226
+ to get
227
+
228
+ +-----------+------+------------+-----------------+
229
+ | City name | Area | Population | Annual Rainfall |
230
+ +-----------+------+------------+-----------------+
231
+ | Darwin | 112 | 120900 | 1714.7 |
232
+ | Hobart | 1357 | 205556 | 619.5 |
233
+ | Adelaide | 1295 | 1158259 | 600.5 |
234
+ | Perth | 5386 | 1554769 | 869.4 |
235
+ | Brisbane | 5905 | 1857594 | 1146.4 |
236
+ | Melbourne | 1566 | 3806092 | 646.9 |
237
+ | Sydney | 2058 | 4336374 | 1214.8 |
238
+ +-----------+------+------------+-----------------+
239
+
240
+ If we want the most populated city to come _first_, we can also give a
241
+ `reversesort=True` argument.
242
+
243
+ If you _always_ want your tables to be sorted in a certain way, you can make
244
+ the setting long term like this:
245
+
246
+ x.sortby = "Population"
247
+ print x
248
+ print x
249
+ print x
250
+
251
+ All three tables printed by this code will be sorted by population (you could
252
+ do `x.reversesort = True` as well, if you wanted). The behaviour will persist
253
+ until you turn it off:
254
+
255
+ x.sortby = None
256
+
257
+ If you want to specify a custom sorting function, you can use the `sort_key`
258
+ keyword argument. Pass this a function which accepts two lists of values
259
+ and returns a negative or positive value depending on whether the first list
260
+ should appeare before or after the second one. If your table has n columns,
261
+ each list will have n+1 elements. Each list corresponds to one row of the
262
+ table. The first element will be whatever data is in the relevant row, in
263
+ the column specified by the `sort_by` argument. The remaining n elements
264
+ are the data in each of the table's columns, in order, including a repeated
265
+ instance of the data in the `sort_by` column.
266
+
267
+ = Changing the appearance of your table - the easy way =
268
+
269
+ By default, PrettyTable produces ASCII tables that look like the ones used in
270
+ SQL database shells. But if can print them in a variety of other formats as
271
+ well. If the format you want to use is common, PrettyTable makes this very
272
+ easy for you to do using the `set_style` method. If you want to produce an
273
+ uncommon table, you'll have to do things slightly harder (see later).
274
+
275
+ == Setting a table style ==
276
+
277
+ You can set the style for your table using the `set_style` method before any
278
+ calls to `print` or `get_string`. Here's how to print a table in a format
279
+ which works nicely with Microsoft Word's "Convert to table" feature:
280
+
281
+ from prettytable import MSWORD_FRIENDLY
282
+ x.set_style(MSWORD_FRIENDLY)
283
+ print x
284
+
285
+ In addition to `MSWORD_FRIENDLY` there are currently two other in-built styles
286
+ you can use for your tables:
287
+
288
+ * `DEFAULT` - The default look, used to undo any style changes you may have
289
+ made
290
+ * `PLAIN_COLUMN` - A borderless style that works well with command line
291
+ programs for columnar data
292
+
293
+ Other styles are likely to appear in future releases.
294
+
295
+ = Changing the appearance of your table - the hard way =
296
+
297
+ If you want to display your table in a style other than one of the in-built
298
+ styles listed above, you'll have to set things up the hard way.
299
+
300
+ Don't worry, it's not really that hard!
301
+
302
+ == Style options ==
303
+
304
+ PrettyTable has a number of style options which control various aspects of how
305
+ tables are displayed. You have the freedom to set each of these options
306
+ individually to whatever you prefer. The `set_style` method just does this
307
+ automatically for you.
308
+
309
+ The options are these:
310
+
311
+ * `border` - A boolean option (must be `True` or `False`). Controls whether
312
+ or not a border is drawn around the table.
313
+ * `header` - A boolean option (must be `True` or `False`). Controls whether
314
+ or not the first row of the table is a header showing the names of all the
315
+ fields.
316
+ * `hrules` - Controls printing of horizontal rules after rows. Allowed
317
+ values: FRAME, ALL, NONE - note that these are variables defined inside the
318
+ `prettytable` module so make sure you import them or use `prettytable.FRAME`
319
+ etc.
320
+ * `int_format` - A string which controls the way integer data is printed.
321
+ This works like: print "%<int_format>d" % data
322
+ * `float_format` - A string which controls the way floating point data is
323
+ printed. This works like: print "%<int_format>f" % data
324
+ * `padding_width` - Number of spaces on either side of column data (only used
325
+ if left and right paddings are None).
326
+ * `left_padding_width` - Number of spaces on left hand side of column data.
327
+ * `right_padding_width` - Number of spaces on right hand side of column data.
328
+ * `vertical_char` - Single character string used to draw vertical lines.
329
+ Default is `|`.
330
+ * `horizontal_char` - Single character string used to draw horizontal lines.
331
+ Default is `-`.
332
+ * `junction_char` - Single character string used to draw line junctions.
333
+ Default is `+`.
334
+
335
+ You can set the style options to your own settings in two ways:
336
+
337
+ == Setting style options for the long term ==
338
+
339
+ If you want to print your table with a different style several times, you can
340
+ set your option for the "long term" just by changing the appropriate
341
+ attributes. If you never want your tables to have borders you can do this:
342
+
343
+ x.border = False
344
+ print x
345
+ print x
346
+ print x
347
+
348
+ Neither of the 3 tables printed by this will have borders, even if you do
349
+ things like add extra rows inbetween them. The lack of borders will last until
350
+ you do:
351
+
352
+ x.border = True
353
+
354
+ to turn them on again. This sort of long term setting is exactly how
355
+ `set_style` works. `set_style` just sets a bunch of attributes to pre-set
356
+ values for you.
357
+
358
+ Note that if you know what style options you want at the moment you are
359
+ creating your table, you can specify them using keyword arguments to the
360
+ constructor. For example, the following two code blocks are equivalent:
361
+
362
+ x = PrettyTable()
363
+ x.border = False
364
+ x.header = False
365
+ x.padding_width = 5
366
+
367
+ x = PrettyTable(border=False, header=False, padding_width=5)
368
+
369
+ == Changing style options just once ==
370
+
371
+ If you don't want to make long term style changes by changing an attribute like
372
+ in the previous section, you can make changes that last for just one
373
+ ``get_string`` by giving those methods keyword arguments. To print two
374
+ "normal" tables with one borderless table between them, you could do this:
375
+
376
+ print x
377
+ print x.get_string(border=False)
378
+ print x
379
+
380
+ = Displaying your table in HTML form =
381
+
382
+ PrettyTable will also print your tables in HTML form, as `<table>`s. Just like
383
+ in ASCII form, you can actually print your table - just use `print_html()` - or
384
+ get a string representation - just use `get_html_string()`. HTML printing
385
+ supports the `fields`, `start`, `end`, `sortby` and `reversesort` arguments in
386
+ exactly the same way as ASCII printing.
387
+
388
+ == Styling HTML tables ==
389
+
390
+ By default, PrettyTable outputs HTML for "vanilla" tables. The HTML code is
391
+ quite simple. It looks like this:
392
+
393
+ <table border="1">
394
+ <tr>
395
+ <th>City name</th>
396
+ <th>Area</th>
397
+ <th>Population</th>
398
+ <th>Annual Rainfall</th>
399
+ </tr>
400
+ <tr>
401
+ <td>Adelaide</td>
402
+ <td>1295</td>
403
+ <td>1158259</td>
404
+ <td>600.5</td>
405
+ <tr>
406
+ <td>Brisbane</td>
407
+ <td>5905</td>
408
+ <td>1857594</td>
409
+ <td>1146.4</td>
410
+ ...
411
+ ...
412
+ ...
413
+ </table>
414
+
415
+ If you like, you can ask PrettyTable to do its best to mimick the style options
416
+ that your table has set using inline CSS. This is done by giving a
417
+ `format=True` keyword argument to either the `print_html` or `get_html_string`
418
+ methods. Note that if you _always_ want to print formatted HTML you can do:
419
+
420
+ x.format = True
421
+
422
+ and the setting will persist until you turn it off.
423
+
424
+ Just like with ASCII tables, if you want to change the table's style for just
425
+ one `print_html` or one `get_html_string` you can pass those methods keyword
426
+ arguments - exactly like `print` and `get_string`.
427
+
428
+ == Setting HTML attributes ==
429
+
430
+ You can provide a dictionary of HTML attribute name/value pairs to the
431
+ `print_html` and `get_html_string` methods using the `attributes` keyword
432
+ argument. This lets you specify common HTML attributes like `name`, `id` and
433
+ `class` that can be used for linking to your tables or customising their
434
+ appearance using CSS. For example:
435
+
436
+ x.print_html(attributes={"name":"my_table", "class":"red_table"})
437
+
438
+ will print:
439
+
440
+ <table border="1" name="my_table" class="red_table">
441
+ <tr>
442
+ <th>City name</th>
443
+ <th>Area</th>
444
+ <th>Population</th>
445
+ <th>Annual Rainfall</th>
446
+ </tr>
447
+ ...
448
+ ...
449
+ ...
450
+ </table>
451
+
452
+ = Miscellaneous things =
453
+
454
+ == Copying a table ==
455
+
456
+ You can call the `copy` method on a PrettyTable object without arguments to
457
+ return an identical independent copy of the table.
458
+
459
+ If you want a copy of a PrettyTable object with just a subset of the rows,
460
+ you can use list slicing notation:
461
+
462
+ new_table = old_table[0:5]
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 1.0
2
+ Name: prettytable
3
+ Version: 0.6.1
4
+ Summary: A simple Python library for easily displaying tabular data in a visually appealing ASCII table format
5
+ Home-page: http://code.google.com/p/prettytable
6
+ Author: Luke Maurits
7
+ Author-email: luke@maurits.id.au
8
+ License: BSD (3 clause)
9
+ Description: UNKNOWN
10
+ Platform: UNKNOWN
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 2.6
13
+ Classifier: Programming Language :: Python :: 2.7
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: License :: OSI Approved :: BSD License
16
+ Classifier: Topic :: Text Processing
@@ -1,4 +1,9 @@
1
+ CHANGELOG
2
+ COPYING
3
+ MANIFEST.in
4
+ README
1
5
  prettytable.py
6
+ prettytable_test.py
2
7
  setup.py
3
8
  prettytable.egg-info/PKG-INFO
4
9
  prettytable.egg-info/SOURCES.txt