trexcheng / prettytable Goto Github PK
View Code? Open in Web Editor NEWAutomatically exported from code.google.com/p/prettytable
License: Other
Automatically exported from code.google.com/p/prettytable
License: Other
What steps will reproduce the problem?
1. Set header field to left table.align["xyz"] = "l"
2. Wrap header field with ansi colors table.header(['\033[34mxyz\033[0m'])
3. Print table
What is the expected output? What do you see instead?
All the values under field xyz should be aligned to the left, but they're
instead aligned at the center.
What version of the product are you using? On what operating system?
Python 2.7.2 OS X 10.8.4 prettytable (0.7.2)
Please provide any additional information below.
It would be a nice feature to be able to add color to fields and values.
Original issue reported on code.google.com by [email protected]
on 21 Aug 2013 at 4:26
In _get_rows, a slice occurs before any sorting takes place. I expected the
slice to occur after. I am requesting a feature that forces the sort to happen
before the slice.
Original issue reported on code.google.com by [email protected]
on 3 May 2013 at 7:57
Wiki says that sortby behaviour can be swich off by setting it to None:
The behaviour will persist until you turn it off:
x.sortby = None
But this raises an error:
In [57]: x.sortby = None
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-57-8471354fb9c4> in <module>()
----> 1 x.sortby = None
/usr/lib/python2.7/site-packages/prettytable.pyc in _set_sortby(self, val)
373 return self._sortby
374 def _set_sortby(self, val):
--> 375 self._validate_option("sortby", val)
376 self._sortby = val
377 sortby = property(_get_sortby, _set_sortby)
/usr/lib/python2.7/site-packages/prettytable.pyc in _validate_option(self,
option, val)
202 self._validate_nonnegative_int(option, val)
203 elif option in ("sortby"):
--> 204 self._validate_field_name(option, val)
205 elif option in ("sort_key"):
206 self._validate_function(option, val)
/usr/lib/python2.7/site-packages/prettytable.pyc in _validate_field_name(self,
name, val)
278 assert val in self._field_names
279 except AssertionError:
--> 280 raise Exception("Invalid field name: %s!" % val)
281
282 def _validate_all_field_names(self, name, val):
Exception: Invalid field name: None!
Original issue reported on code.google.com by [email protected]
on 29 Oct 2012 at 9:02
By design, PrettyTables forbids duplicate field names. But this very case
naturally occurs in any table returned by an unfiltered cross product SQL
request, e.g.:
cursor = c.execute("SELECT * FROM foobar A, foobar B")
t = prettytable.from_db_cursor(cursor)
Can you add an option to override the check for uniqueness?
Thanks!
Original issue reported on code.google.com by aristide.grange
on 8 Oct 2013 at 7:57
would be great if you could add support for termcolor so users can pass column
values as
from termcolor import colored
from prettytable import PrettyTable
. . .
x.add_row([colored(my_var, 'red'), ... ])
if you do that currently, the value will be highlighted, the table formatting
however will be broken
Original issue reported on code.google.com by mockba
on 23 Jan 2013 at 8:48
Is this something that has being considered for future versions? It'd be
really nice if a format spec could be supplied for the formatting of all floats
in a column or table e.g.
my_pretty_table.float_format_spec("4.2")
Original issue reported on code.google.com by [email protected]
on 28 Feb 2012 at 11:22
What steps will reproduce the problem?
1. Run tests on Python 2.4
What is the expected output? What do you see instead?
Tests should pass. Instead, slicing tests fail:
+ /usr/bin/python prettytable_test.py
...............................EE...
======================================================================
ERROR: testSliceFirstTwoRows (__main__.SlicingTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "prettytable_test.py", line 192, in testSliceFirstTwoRows
y = self.x[0:2]
File "/builddir/build/BUILD/prettytable-0.6.1/prettytable.py", line 171, in __getitem__
newtable = copy.deepcopy(self)
File "/usr/lib64/python2.4/copy.py", line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.4/copy.py", line 351, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python2.4/copy.py", line 174, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python2.4/copy.py", line 268, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python2.4/copy.py", line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.4/copy.py", line 336, in _reconstruct
y = callable(*args)
File "/usr/lib64/python2.4/copy_reg.py", line 92, in __newobj__
return cls.__new__(cls, *args)
TypeError: function() takes at least 2 arguments (0 given)
======================================================================
ERROR: testSliceLastTwoRows (__main__.SlicingTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "prettytable_test.py", line 201, in testSliceLastTwoRows
y = self.x[-2:]
File "/builddir/build/BUILD/prettytable-0.6.1/prettytable.py", line 171, in __getitem__
newtable = copy.deepcopy(self)
File "/usr/lib64/python2.4/copy.py", line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.4/copy.py", line 351, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib64/python2.4/copy.py", line 174, in deepcopy
y = copier(x, memo)
File "/usr/lib64/python2.4/copy.py", line 268, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib64/python2.4/copy.py", line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib64/python2.4/copy.py", line 336, in _reconstruct
y = callable(*args)
File "/usr/lib64/python2.4/copy_reg.py", line 92, in __newobj__
return cls.__new__(cls, *args)
TypeError: function() takes at least 2 arguments (0 given)
----------------------------------------------------------------------
Ran 36 tests in 0.050s
FAILED (errors=2)
What version of the product are you using? On what operating system?
prettytable-0.6.1, python-2.4.3 (RHEL5)
Please provide any additional information below.
This patch fixes the test suite, and it should be safe to use None because
.sort() accepts None for the key. But I think it will still break if the caller
slices a PrettyTable with a custom sort_key set on it. It might be necessary to
write a custom __deepcopy__ or avoid using deepcopy.
diff -ur prettytable-0.6.1.orig/prettytable.py
prettytable-0.6.1.patched/prettytable.py
--- prettytable-0.6.1.orig/prettytable.py 2012-06-04 08:22:23.000000000 +1000
+++ prettytable-0.6.1.patched/prettytable.py 2013-11-19 08:26:01.231044684 +1000
@@ -137,7 +137,7 @@
self._sortby = kwargs["sortby"] or None
self._reversesort = kwargs["reversesort"] or False
- self._sort_key = kwargs["sort_key"] or (lambda x: x)
+ self._sort_key = kwargs["sort_key"]
self._int_format = kwargs["float_format"] or {}
self._float_format = kwargs["float_format"] or {}
Original issue reported on code.google.com by [email protected]
on 18 Nov 2013 at 10:31
Hello,
I would like to request option to set minimum column width
Sample:
x.set_field_names(["City name", "Area"])
x.add_row(["Adelaide",1295])
x.add_row(["Brisbane",5905])
x.align["City name"] = 'l'
x.min_width["City name"] = 30
Will end:
+--------------------------------+------+
| City name | Area |
+--------------------------------+------+
| Adelaide | 1295 |
| Brisbane | 5905 |
+--------------------------------+------+
or
set table min width and provide column to expand:
x.min_width(60, "City name")
Will give:
+---------------------------------------------------+------+
| City name | Area |
+---------------------------------------------------+------+
| Adelaide | 1295 |
| Brisbane | 5905 |
+---------------------------------------------------+------+
Best regards
Original issue reported on code.google.com by [email protected]
on 5 Oct 2012 at 6:45
# Import the SQLite3 module
import sqlite3
db = sqlite3.connect('book.db')
db_cur = db.cursor()
db_cur.execute('''CREATE TABLE IF NOT EXISTS novel(id INTEGER PRIMARY KEY,
title TEXT, author TEXT, year INT)''')
novel = [
('As I Lay Dying', 'William Faulkner', '1930'),
('Lullaby', 'Chuck Palanhuik', '2003'),
('Fight Club', 'Chuck Palanhuik', '2000'),
('Sex','Madonna', '1998'),
('Survivor','Chuck Palanhuik', '2002'),
('Cats Cradle', 'Kurt Vonnegut', '1967'),
('Slaughterhouse Five', 'Kurt Vonnegut', '1956')
]
db_cur.executemany('''INSERT INTO novel("TITLE", "AUTHOR", "YEAR")
VALUES(?,?,?)''', novel)
db.commit()
print "Operation done successfully";
from prettytable import from_db_cursor
db.execute("SELECT * FROM novel")
pt = from_db_cursor(db_cur)
db.close()
print pt.get_string(sortby = "TITLE")
On Python 2.7, this brings back as AttributeError: 'NoneType' object has no
attribute 'get_string'.
If I just print pt,
I get this:
+-----+---------------------+------------------+------+
| id | title | author | year |
+-----+---------------------+------------------+------+
| 1 | As I Lay Dying | William Faulkner | 1930 |
| 2 | Lullaby | Chuck Palanhuik | 2003 |
| 3 | Fight Club | Chuck Palanhuik | 2000 |
| 4 | Sex | Madonna | 1998 |
| 5 | As I Lay Dying | William Faulkner | 1930 |
| 6 | Lullaby | Chuck Palanhuik | 2003 |
| 7 | Fight Club | Chuck Palanhuik | 2000 |
| 8 | Sex | Madonna | 1998 |
| 9 | As I Lay Dying | William Faulkner | 1930 |
| 10 | Lullaby | Chuck Palanhuik | 2003 |
all the way to like 300. there are only seven entries.
HELP!!
Original issue reported on code.google.com by [email protected]
on 18 Jan 2014 at 1:58
What steps will reproduce the problem?
1. Download the package from
https://prettytable.googlecode.com/files/prettytable-0.7.2.tar.gz
2. Extract and notice the permission for all files, especially the ones under
prettytable.egg-info directory
3. They should be readable by group/others.
What is the expected output? What do you see instead?
rainbow:Downloads barumugam$ tar -jxf prettytable-0.7.2.tar.bz2 && ls -lrt
prettytable-0.7.2/prettytable.egg-info/
total 32
-rw-------@ 1 barumugam staff 12 Apr 6 18:30 top_level.txt
-rw-------@ 1 barumugam staff 1 Apr 6 18:30 dependency_links.txt
-rw-------@ 1 barumugam staff 220 Apr 6 18:30 SOURCES.txt
-rw-------@ 1 barumugam staff 710 Apr 6 18:30 PKG-INFO
What version of the product are you using? On what operating system?
0.7.2
The permission is wrong in the tar file. No matter which OS we use to extract,
the permission is wrong. Due to this issue, if we install any library using pip
as non-root user, it fail with following error. This one occur precisely when
we install MySQL-python using pip, wherein prettytable is one of requirements.
The issue seem to exist even in older versions, say: 0.7.1.
File "/tmp/tmp2wlMmf/distribute-0.6.28/pkg_resources.py", line 1320, in _get
stream = open(path, 'rb')
IOError: [Errno 13] Permission denied:
'/usr/local/csi/lib/python2.6/site-packages/prettytable-0.7.2-py2.6.egg-info/top
_level.txt'
/home/jenkins/workspace/csi-nova-upstream/.tox/py26/build/MySQL-python/distribut
e-0.6.28-py2.6.egg
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/jenkins/workspace/csi-nova-upstream/.tox/py26/build/MySQL-python/setup.py", line 7, in <module>
use_setuptools()
File "distribute_setup.py", line 145, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "distribute_setup.py", line 125, in _do_download
_build_egg(egg, tarball, to_dir)
File "distribute_setup.py", line 116, in _build_egg
raise IOError('Could not build the egg.')
IOError: Could not build the egg.
Can you please fix it or regenerate the package with right permission for these
files?
Thank you,
Bhuvan
Original issue reported on code.google.com by [email protected]
on 28 Aug 2013 at 9:13
When installing prettytable 0.6 using setuptools on a system that already has
prettytable 0.5 installed, I get an import error about __version__. This is
because setup.py tries to import __version__ from prettytable.py, but it finds
the 0.5 prettytable.py in the path first. The 0.5 version doesn't have
__version__.
I think you should probably hard code the version in setup.py instead of trying
to import it from prettytable.py. That would fix the problem.
Original issue reported on code.google.com by [email protected]
on 19 Jul 2012 at 12:03
Hello,
when preparing the Debian package, and building the package in a clean chroot,
I'm getting this error:
testPrint (prettytable_test.PrintJapanestTest) ... ERROR
testSliceAll (prettytable_test.SlicingTests) ... ok
testSliceFirstTwoRows (prettytable_test.SlicingTests) ... ok
testSliceLastTwoRows (prettytable_test.SlicingTests) ... ok
testReverseSort (prettytable_test.SortingTests) ... ok
testSortBy (prettytable_test.SortingTests) ... ok
testSortKey (prettytable_test.SortingTests) ... ok
======================================================================
ERROR: testPrint (prettytable_test.PrintJapanestTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/buildd/prettytable-0.7/prettytable_test.py", line 566, in testPrint
print(self.x)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 108-109:
ordinal not in range(128)
----------------------------------------------------------------------
Ran 49 tests in 0.079s
FAILED (errors=1)
which is weird, given I can run it fine outside the chroot, but I want to ask
you if you know more.
Cheers,
Sandro
Original issue reported on code.google.com by sandro.tosi
on 21 Feb 2013 at 9:39
The differences between %f and %g are described here:
http://stackoverflow.com/questions/5913102/what-is-the-difference-between-g-and-
f-in-c
I am attaching a simple program to illustrate some differences on real data.
Here is the output:
+---------------+------------------+--------------+-------------+
| default | floatFmt1 | floatFmt2 | gFmt |
+---------------+------------------+--------------+-------------+
| 123456789.123 | 123456789.123400 | 123456789.12 | 1.23457e+08 |
| 0.000122 | 0.000122 | 0.00 | 0.000122 |
| 23 | 23.000000 | 23.00 | 23 |
| 1.01010101 | 1.010101 | 1.01 | 1.0101 |
+---------------+------------------+--------------+-------------+
Original issue reported on code.google.com by [email protected]
on 24 Nov 2013 at 7:16
Attachments:
Hi,
I tried the "hard way" for installing in Windows, but, altough I can do import
prettytable, I cannot access the inside functions neither cant do from
prettytable import modules (tried with PrettyTable and from_db_cursor).
I am missing something?
I've just copied the folder inside site-packages, renaming it to prettytable.
Thanks in advance.
Josep
Original issue reported on code.google.com by [email protected]
on 1 Oct 2013 at 10:45
0.6 RC1
On line 873, for row in self_rows should be for row in rows, otherwise it
ignores sorting.
Original issue reported on code.google.com by [email protected]
on 24 Aug 2009 at 6:15
What steps will reproduce the problem?
1. install the module
2. try to use it with flask
3. get error
What is the expected output? What do you see instead?
+------+------------+---------+ | Name | Phone | Yardage |
+------+------------+---------+ | John | 7193382296 | 27 | | John | 7193382296
| 27 | +------+------------+---------+
What version of the product are you using? On what operating system?
Latest mac OSX
Please provide any additional information below.
Original issue reported on code.google.com by pilotkid2011
on 14 Dec 2013 at 11:24
What steps will reproduce the problem?
1. Create a new instance with PrettyTable(border=False)
2. print the table
What is the expected output? What do you see instead?
The keyword argument `border` is ignored. I would expect a table without border
to be printed out. Instead a table with the border is printed.
Original issue reported on code.google.com by [email protected]
on 19 Jan 2013 at 11:18
What steps will reproduce the problem?
1. Followed the 'hard-way installation' on Windows with python27
2. imported module like this: 'import prettytable'
3. created new instance like this: 'myTable = PrettyTable()'
=> NameError: name 'PrettyTable' is not defined
Version: Tried with RC01 and 0.7.2
What am I doing wrong here?
Thanks
Original issue reported on code.google.com by [email protected]
on 26 Aug 2013 at 12:51
What steps will reproduce the problem?
1.is it possible to get the row with out field name?
+-----------+------------+
| City name | Population |
+-----------+------------+
| Brisbane | 1857594 |
| Darwin | 120900 |
| Hobart | 205556 |
| Sydney | 4336374 |
+-----------+------------+
if i select the 1 row it has to show only second row as output without field
names?
print Tablename.getstring(1)
o/p:
| Brisbane | 1857594 |
Original issue reported on code.google.com by [email protected]
on 12 Dec 2013 at 9:24
What steps will reproduce the problem?
1.open the test script.
2.add "Chinese" colum in head
3.add more cloum "阿斯达" to each row. run the test script.
What is the expected output? What do you see instead?
+--------+------------+----------+---------+
| Kanji | Hiragana | English | Chinese |
+--------+------------+----------+---------+
| 神戸 | こうべ | Kobe | 阿斯达 |
| 京都 | きょうと | Kyoto | 阿斯达 |
| 長崎 | ながさき | Nagasaki | 阿斯达 |
| 名古屋 | なごや | Nagoya | 阿斯达 |
| 大阪 | おおさか | Osaka | 阿斯达 |
| 札幌 | さっぽろ | Sapporo | 阿斯达 |
| 東京 | とうきょう | Tokyo | 阿斯达 |
| 横浜 | よこはま | Yokohama | 阿斯达 |
+--------+------------+----------+---------+
Instead:
+--------+------------+----------+---------+
| Kanji | Hiragana | English | Chinese |
+--------+------------+----------+---------+
| 神戸 | こうべ | Kobe | 阿斯达 |
| 京都 | きょうと | Kyoto | 阿斯达 |
| 長崎 | ながさき | Nagasaki | 阿斯达 |
| 名古屋 | なごや | Nagoya | 阿斯达 |
| 大阪 | おおさか | Osaka | 阿斯达 |
| 札幌 | さっぽろ | Sapporo | 阿斯达 |
| 東京 | とうきょう | Tokyo | 阿斯达 |
| 横浜 | よこはま | Yokohama | 阿斯达 |
+--------+------------+----------+---------+| とうきょう | Tokyo |
阿斯达 |
| 横浜 | よこはま | Yokohama | 阿斯达 |
+--------+------------+----------+---------+------------+----------+---------+
code(changed):
class PrintJapanestTest(unittest.TestCase):
def setUp(self):
self.x = PrettyTable(["Kanji", "Hiragana", "English", "Chinese"])
self.x.add_row(["神戸", "こうべ", "Kobe", "阿斯达"])
self.x.add_row(["京都", "きょうと", "Kyoto", "阿斯达"])
self.x.add_row(["長崎", "ながさき", "Nagasaki", "阿斯达"])
self.x.add_row(["名古屋", "なごや", "Nagoya", "阿斯达"])
self.x.add_row(["大阪", "おおさか", "Osaka", "阿斯达"])
self.x.add_row(["札幌", "さっぽろ", "Sapporo", "阿斯达"])
self.x.add_row(["東京", "とうきょう", "Tokyo", "阿斯达"])
self.x.add_row(["横浜", "よこはま", "Yokohama", "阿斯达"])
def testPrint(self):
print()
print(self.x)
What version of the product are you using? On what operating system?
v0.7.2 Win7 x86
Please provide any additional information below.
modify the main script ,the main method to test, also has problom.
shows:
+--------------------+-------+------------+-----------------+
| City name | Area | Population | Annual Rainfall |
+--------------------+-------+------------+-----------------+
| Sydney | 2058d | 4336374 | 1214.8f |
| Perth | 5386d | 1554769 | 869.4f |
| Melbourne | 1566d | 3806092 | 646.9f |
| Hobart | 1357d | 205556 | 619.5f |
| Darwin啊大声大声道 | 0112d | 120900 | 1714.7f |
| Brisbane | 5905d | 1857594 | 1146.4f |
| Adel我啊是 | 1295d | 1158259 | 600.5f |
+--------------------+-------+------------+-----------------+-----------------+
extra one cloum in last row.
Original issue reported on code.google.com by [email protected]
on 21 Nov 2013 at 8:43
One very useful feature for displaying numerical data is aligning on the
decimal point. Implementing this is, of course, quite nontrivial, but
prettytable would be the ideal location for such code.
Original issue reported on code.google.com by [email protected]
on 26 May 2009 at 4:19
Hi, would be nice to have python3 support!
I attached a patch made with 2to3, here is the output:
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: Refactored prettytable.py
RefactoringTool: Files that need to be modified:
RefactoringTool: prettytable.py
Original issue reported on code.google.com by [email protected]
on 9 Nov 2010 at 8:21
Attachments:
The tutorial on the Wiki is out of date. Atleast:
x.set_field_align("City name", "l")
should be:
x.align["City name"] = 'l'
There may be others too.
Cheers!
Original issue reported on code.google.com by [email protected]
on 10 Aug 2012 at 2:03
when i call pt.printt(sort='something')
it's only return "printt"
and it's not happen at 0.5 version
Original issue reported on code.google.com by [email protected]
on 9 May 2012 at 4:55
Hi,
Do you think it could be easy to espace bash color codes like that ?
'\033[1;37;40mHello World\033[2;32;40m'
Cause at this time, prettytable count each characters to set column width.
Best regards,
Socketubs.
Original issue reported on code.google.com by [email protected]
on 26 Oct 2012 at 9:36
Hello,
it would be useful to have also the mentioned files in the released tarball: a
changelog is handy to users to know what changes between releases, and a test
unit is handy for packagers to verity the module is working all fine.
Cheers,
Sandro
Original issue reported on code.google.com by sandro.tosi
on 6 May 2012 at 7:59
A way to specify maximal width of a column would be nice. If there is more
content then space, the content should wrap to the next line.
Original issue reported on code.google.com by tibor.arpas
on 13 Jun 2009 at 11:56
It would be nice if prettytable also could print a footer for a table. In my
case it are the totals for each column.
Original issue reported on code.google.com by [email protected]
on 9 Feb 2014 at 10:09
An enhancement request for an option that will cause a title to be displayed.
+--------------------------+
| Neat Example |
+------------+-------------+
| Column | And another |
+------------+-------------+
Original issue reported on code.google.com by [email protected]
on 10 May 2013 at 8:13
Hello,
I would like to create Pandoc Markdown compliant grid tables. For this I just
need to be able to change the header horizontal character to '=' while leaving
the table borders and column separators at '-'
I think this small change would be an excellent addition. Thanks very much for
your great library.
Original issue reported on code.google.com by [email protected]
on 25 Sep 2013 at 6:57
In 0.6-RC01, the result of get_html_string() only includes closing </tr>
tags at the end of the header row and the end of the table.
While suitable for browsers, the resulting html cannot be parsed by
xml.etree for further processing.
Original issue reported on code.google.com by [email protected]
on 23 Sep 2009 at 10:04
What steps will reproduce the problem?
1. printt is gone but the tutorials still refer to it.
2. Since other code (e.g., python-socialtext) uses printt, document that printt
was replaced by get_string.
3.
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 15 Jun 2012 at 9:56
If get_html_string() is called with formatted=True and there are table cells
with line breaks in them, the returned HTML representation uses "<br/>" for
line breaks. This is valid XHTML but not valid HTML (which needs "<br>"). It
should be possible for the user to select which of these they want.
Original issue reported on code.google.com by [email protected]
on 22 Jan 2013 at 1:43
What steps will reproduce the problem?
prettytable.from_html('<table><tr><td>one</td><td>two</td></tr><tr><td
colspan="2">three</td></tr></table>')
What is the expected output? What do you see instead?
Ideally I'd hope to see a table that prints to
+---------+---------+
| Field 1 | Field 2 |
+---------+---------+
| one | two |
| three |
+---------+---------+
but I'd settle for
+---------+---------+
| Field 1 | Field 2 |
+---------+---------+
| one | two |
| three | |
+---------+---------+
What I get instead is
Exception: Row has incorrect number of values, (actual) 1!=2 (expected)
What version of the product are you using? On what operating system?
0.7.2 on Ubuntu 13.04
Original issue reported on code.google.com by [email protected]
on 26 Aug 2013 at 10:46
What steps will reproduce the problem?
1. Install current prettytable
2. Run the following in a Python shell:
>>> import prettytable
>>> pt = prettytable.PrettyTable()
>>> pt.set_field_names
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/prettytable.py", line 163, in __getattr__
raise AttributeError(name)
AttributeError: set_field_names
What is the expected output? What do you see instead?
This works in prettytable 0.5
Original issue reported on code.google.com by [email protected]
on 21 Nov 2012 at 2:06
please save the attachment "test.ansi",and to see the displayed table in my
console.
from prettytable import PrettyTable
fh= open("test.ansi", "r",encoding="gbk")
header=fh.readline().strip().split(",")
x = PrettyTable(header)
x.align["乘客姓名"]="l"
for row in fh.readlines():
x.add_row(row.strip().split(","))
print(x)
Original issue reported on code.google.com by [email protected]
on 12 Apr 2014 at 7:25
Attachments:
Hi, this is a request for an enhancement. I would like to be able to print
these two kind of tables, but as far as I understand this is currently not
possible with prettytable:
header1 header2 header3
===========================
x1y1 x2y1 x3y1
x1y2 x2y2 x3y2
x1y3 x2y3 x3y3
i.e. only an hrule under the header (possibly, updating the character used)
And also the following syntax is quite common:
+----------------------------+
| header1 header2 header3 |
+============================+
| x1y1 x2y1 x3y1 |
| x1y2 x2y2 x3y2 |
| x1y3 x2y3 x3y3 |
+----------------------------+
i.e. a frame around the table, and a different horizontal rule under the header.
Original issue reported on code.google.com by [email protected]
on 19 Jan 2013 at 9:40
Sometimes tables may become too large to fit on the terminal screen, in these
cases, it is nice to be able to print out the table in a vertical format
(similar to MySQL's \G option)
Here's a basic function -- would you be able to incorporate some sort of
similar functionality in prettytable?
def format_pretty_table_vertically(table):
'''Given a PrettyTable table instance, format each row vertically (similar to mysql's \G display)'''
formatted = []
max_field_width = max([len(x) for x in table._field_names])
for row_i, row in enumerate(table._rows):
formatted.append('*************************** %i. row ***************************' % (row_i + 1, ))
for i, field in enumerate(table._field_names):
formatted.append("%s: %s" % (field.rjust(max_field_width), row[i]))
return '\n'.join(formatted)
sample output:
*************************** 1. row ***************************
People Sampled: 7294
Location: North Pole
Min Happiness: 1.7
Avg Happiness: 3.7
Max Happiness: 7.3
*************************** 2. row ***************************
People Sampled: 4321
Location: South Pole
Min Happiness: 3.2
Avg Happiness: 5.2
Max Happiness: 8.6
Thanks,
Alex
Original issue reported on code.google.com by [email protected]
on 18 Dec 2013 at 6:06
Hi,
PrettyTable don't support breakline in cell.
I would like to do :
t.add_row(['foo', 'bar\nsecond line'])
and output :
+---+-----------+
|foo|bar |
| |second line|
+---+-----------+
Regards,
Stephane
Original issue reported on code.google.com by klein.stephane
on 2 Mar 2010 at 4:25
Hi,
I use the pretty table and frequently find myself where I would like to sort
the table using a key function, currently I cannot do it inside prettytable,
and I have have to either construct it after all my sorting or deconstruct,
sort and reconstruct the table.
Would it be possible to add this feature? If you want I can take a crack at it
and submit a patch.
Thanks
Aman
Original issue reported on code.google.com by [email protected]
on 6 Jan 2012 at 4:20
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 [email protected]
on 29 Mar 2013 at 12:00
Currently many people use pretty table to create nice ASCII tables, which is
great, but then there is a set of people who want to read that ASCII format
back into python. It might be useful to associate with each ASCII table
generator class a way to reverse said ASCII table back into a dictionary.
Original issue reported on code.google.com by [email protected]
on 19 Mar 2013 at 12:41
here is data you can test .
Original issue reported on code.google.com by [email protected]
on 12 Apr 2014 at 7:28
Attachments:
What steps will reproduce the problem?
1. pipe = subprocess.os.popen('lp','w')
2. pipe.write(table.get_string())
3. pipe.close()
What is the expected output? What do you see instead?
Headers appear on first page only. It would be nice to be able to paginate for
some number of lines per pate
What version of the product are you using? On what operating system?
0.7.2
Please provide any additional information below.
Example of code attached. There may be a need to specify columns per page as
well.
Original issue reported on code.google.com by [email protected]
on 21 Jul 2013 at 11:06
Setting max_with (e.g. "my_table.max_with = 800") will cause an exception like
this:
Traceback (most recent call last):
...
File "prettytable.py", line 333, in _set_max_width
self._validate_nonnegativeint(val)
File "prettytable.py", line 163, in __getattr__
raise AttributeError(name)
AttributeError: _validate_nonnegativeint
because _validate_nonnegativeint(...) is unknown in class PrettyTable.
I assume that _validate_nonnegative_int(...) is meant here.
Original issue reported on code.google.com by [email protected]
on 30 Oct 2012 at 6:07
What steps will reproduce the problem?
import prettytable
pt = prettytable.PrettyTable('a b c'.split())
pt.add_row([1,2,3])
pt.add_row([4,5,6])
pt.printt() # Works as expected
# Now let's change the headers...
pt.field_names = "aaa bbb ccc".split()
pt.printt() # oops!
# This gets printed:
+---+---+---+
| aaa | bbb | ccc |
+---+---+---+
| 1 | 2 | 3 |
| 4 | 5 | 6 |
+---+---+---+
# Setting the headers a second time fixes this issue:
pt.field_names = "aaa bbb ccc".split()
pt.printt()
+-----+-----+-----+
| aaa | bbb | ccc |
+-----+-----+-----+
| 1 | 2 | 3 |
| 4 | 5 | 6 |
+-----+-----+-----+
I believe this happens because self._recompute_widths() is called before
setting the new value for _field_names.
Tested with:
* prettytable SVN revision 36
* Python 2.6
Original issue reported on code.google.com by denilsonsa
on 17 Jan 2011 at 5:51
I am attaching a simple program that attempts to use the
p.align="r"
option as described in the online tutorial:
http://code.google.com/p/prettytable/wiki/Tutorial
(under per-column settings)
However, it looks like the global setting is ignored.
I am using prettytable 0.7.2 installed via easy_install.
The output of the program is given below:
+---------------+------------------+--------------+-------------+
| default | floatFmt1 | floatFmt2 | gFmt |
+---------------+------------------+--------------+-------------+
| 123456789.123 | 123456789.123400 | 123456789.12 | 1.23457e+08 |
| 0.000122 | 0.000122 | 0.00 | 0.000122 |
| 23 | 23.000000 | 23.00 | 23 |
| 1.01010101 | 1.010101 | 1.01 | 1.0101 |
+---------------+------------------+--------------+-------------+
+---------------+------------------+--------------+-------------+
| default | floatFmt1 | floatFmt2 | gFmt |
+---------------+------------------+--------------+-------------+
| 123456789.123 | 123456789.123400 | 123456789.12 | 1.23457e+08 |
| 0.000122 | 0.000122 | 0.00 | 0.000122 |
| 23 | 23.000000 | 23.00 | 23 |
| 1.01010101 | 1.010101 | 1.01 | 1.0101 |
+---------------+------------------+--------------+-------------+
Original issue reported on code.google.com by [email protected]
on 24 Nov 2013 at 7:21
What steps will reproduce the problem?
1. Use a unicode object containing non-ASCII characters anywhere in a table.
What is the expected output? What do you see instead?
Either UnicodeEncodeError or UnicodeDecodeError.
What version of the product are you using? On what operating system?
Both 0.5 and trunk.
Please provide any additional information below.
There are tons of 'unicode' function calls without the 'encoding' argument
throughout the code, and any string or
unicode object containing non-ASCII characters ruins everything.
Attached a very dumb patch, which just adds a little bit smarter '_unicode' and
replaces all 'unicode' calls with
'_unicode'.
I believe a more clever approach is possible, like converting values once
they're being added (via constructor or
'add_row') thus reducing number of calls to 'unicode' or whatever.
Original issue reported on code.google.com by [email protected]
on 27 Apr 2010 at 4:59
Attachments:
What steps will reproduce the problem?
1. Initial steps if enter asian characters (Japanese) in UTF-8
2.
3.
What is the expected output? What do you see instead?
Expected output = Asian Text
But I see question marks like the following
+----+----+
| ?? | ?? |
+----+----+
| ?? | ?? |
+----+----+
What version of the product are you using? On what operating system?
Latest
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 23 May 2012 at 6:50
Attachments:
Hi,
I'm currently using this lib to generate pretty ascii tables.
I get my data from a csv file where the delimiter is set to ;.
So I think thwe from_csv should take an optional delimiter arg, so it does not
need to guess the dialect. I looked at the code and here is a corrected
function to do this. (Only the first lines of the from_csv function)
def from_csv(fp, field_names = None, delimiter=None,**kwargs):
if delimiter is None:
dialect = csv.Sniffer().sniff(fp.read(1024))
fp.seek(0)
reader = csv.reader(fp, dialiect)
else:
reader = csv.reader(fp, delimiter=delimiter)
the rest is the same
Original issue reported on code.google.com by [email protected]
on 10 Jun 2013 at 8:43
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.