pri22296 / beautifultable Goto Github PK
View Code? Open in Web Editor NEWPython package for printing visually appealing tables on a terminal.
License: MIT License
Python package for printing visually appealing tables on a terminal.
License: MIT License
If detect_numerics is True
, which is by default, then any non-string floats are rounded to integers.
table = BeautifulTable(max_width=30)
table.column_headers = ["name", "rank", "gender"]
table.append_row(["Sophia", 2, "girl"*20])
table.append_row(["Michael", 3, "boy"])
print(table)
| | rank | gender |
| n | | |
| a | | |
| m | | |
| e | | |
+--+------+------------------+
| | 2 | girlgirlgirlgirl |
| S | | girlgirlgirlgirl |
| o | | girlgirlgirlgirl |
| p | | girlgirlgirlgirl |
| h | | girlgirlgirlgirl |
| i | | |
| a | | |
+--+------+------------------+
| | 3 | boy |
| M | | |
| i | | |
| c | | |
| h | | |
| a | | |
| e | | |
| l | | |
+--+------+------------------+```
intersection_char
could be expanded into multiple types based on shape. will allow for more customization. #53>>> from beautifultable import BeautifulTable
>>> table = BeautifulTable()
>>> table.append_row([1])
>>> table.pop_row()
>>> print(table)
+--+
| |
+--+
+--+
>>> table.append_row([1])
>>> table.pop_column()
>>> print(table)
+
||
+
+
When using WEP_ELLIPSIS
or WEP_STRIP
table is malformed when using east asian characters as shown below.
| name | rank | gender |
+--------------------------------+------+--------+
| こんにちはこんにちはこんにちはこんにちはこんにちはこん... | 1 | boy |
+--------------------------------+------+--------+
| Isabella | 1 | girl |
+--------------------------------+------+--------+
| Ethan | 2 | boy |
+--------------------------------+------+--------+
| Sophia | 2 | girl |
+--------------------------------+------+--------+
| Michael | 3 | boy |
+--------------------------------+------+--------+
#1 issue
if we add row value 2.0.
Then it prints 2.
https://github.com/pri22296/beautifultable/blob/master/beautifultable/utils.py#L13
2.0.is_integer()#True
You should return Item.
Not tested if it works locally.
Hello! Don't find the sorting order of table. For example ascending or descending ordering. Is this method in your lib?
This seemed off to me:
python -c "import beautifultable; t = beautifultable.BeautifulTable(); t.append_row(['3.14']); print('%s' % t)"
I get:
+--------------------+
| 3.1400000000000001 |
+--------------------+
when I expect:
+------+
| 3.14 |
+------+
Since I actually specified the row as a string I'm surprised to see was treated as a float (float gives same behavior).
Print prints to terminal. I would need something that can put the output in a string instead.
Hi,
I'm trying to print multibyte string in beautifultable. But the result is not beautiful, unsuitable number of space.
like this:
from beautifultable import BeautifulTable
table = BeautifulTable()
table.column_headers = ['Language', 'Hello']
table.append_row(['Japanese', 'こんにちは'])
table.append_row(['English', 'Hello'])
table.append_row(['Chinese', '你好'])
table.append_row(['Emoji', '😉'])
print(table)
+----------+-------+
| Language | Hello |
+----------+-------+
| Japanese | こんにちは |
+----------+-------+
| English | Hello |
+----------+-------+
| Chinese | 你好 |
+----------+-------+
| Emoji | 😉 |
+----------+-------+
Is there any way to solve this problem?
Thanks.
$ pip freeze | grep beautifultable
beautifultable==0.5.3
Currently prints
+
||
+
+
I encountered this error using beautifultable v0.70 in python2.7.
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-138: ordinal not in range(128)
It occurred during
print(table)
when I used:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
or
from __future__ import unicode_literals
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
It printed nothing but noisy results:
â•â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”
Minimal example:
table = beautifultable.BeautifulTable(max_width=150)
table.column_headers = ['t', 'u', 'v', 'w', 'x', 'y', 'z']
table.append_row(['q123456789012345678', 'a', 'b', 'c', 'd', 'e', 'f'])
print(table)
Output:
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
| t | u | v | w | x | y | z |
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
| q123456789012345678 | a | b | c | d | e | f |
+----------------------------------------------------------------------------------------------------------------------------+---+---+---+---+---+---+
The first column is too wide. If I omit the last character, it works as expected:
table.append_row(['q12345678901234567', 'a', 'b', 'c', 'd', 'e', 'f'])
+--------------------+---+---+---+---+---+---+
| t | u | v | w | x | y | z |
+--------------------+---+---+---+---+---+---+
| q12345678901234567 | a | b | c | d | e | f |
+--------------------+---+---+---+---+---+---+
It also seems to work as expected if I change the max_width
, or if I use fewer columns.
The length of a escape sequence is taken into account when calculating the col-width.
This is a problem when you want to display a colored string.
For example:
open = \033[1;32open\033[0m
-------------------+
open |
-------------------+
After #53 is merged, we can now use different characters for different points of intersections which makes box tables a possibility using unicode characters such as in http://jrgraphix.net/r/Unicode/2500-257F
Currently travis seems to have some issue with 3.7(see travis-ci/travis-ci#9815).
As mentioned in #36, Using collections.Iterable has been deprecated in 3.7 and will stop working in 3.8
Fix should be similar to pyparsing/pyparsing#16
This seems to be breaking on python 2.
>>> import beautifultable
>>> t = beautifultable.BeautifulTable()
>>> t.column_headers = ["a", "b", "c"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/russ/.pyenv/versions/2.7.10/lib/python2.7/site-packages/beautifultable/beautifultable.py", line 231, in __setattr__
super(BeautifulTable, self).__setattr__(name, value)
File "/Users/russ/.pyenv/versions/2.7.10/lib/python2.7/site-packages/beautifultable/beautifultable.py", line 366, in column_headers
raise TypeError("Headers should be of type 'str', not {}".format(type(i)))
TypeError: Headers should be of type 'str', not <type 'str'>
The content and header names for my table are being wrapped. To avoid this, I'm setting table.column_widths, as per the docs, such as
table.column_widths = [30, 30, 30]
But it doesn't seem to have any effect.
Is there are more correct way to establish column widths?
Python 3
+-------+----+-----+
| name | ra | gen |
| | nk | der |
+-------+----+-----+
| Jacob | 1 | boy |
+-------+----+-----+
| Isabe | 1 | gir |
| lla | | l |
+-------+----+-----+
| Ethan | 2 | boy |
+-------+----+-----+
| Sophi | 2 | gir |
| a | | l |
+-------+----+-----+
| Micha | 3 | boy |
| el | | |
+-------+----+-----+
Python 2
+------+----+-----+
| name | ra | gen |
| | nk | der |
+------+----+-----+
| Jaco | 1 | boy |
| b | | |
+------+----+-----+
| Isab | 1 | gir |
| ella | | l |
+------+----+-----+
| Etha | 2 | boy |
| n | | |
+------+----+-----+
| Soph | 2 | gir |
| ia | | l |
+------+----+-----+
| Mich | 3 | boy |
| ael | | |
+------+----+-----+
When header are not explicitly set, the expected behavior should be not to print the header row.
currently, a blank row is printed.
#!/usr/bin/env python3
from beautifultable import BeautifulTable
table = BeautifulTable()
table.column_headers = list(["Name" for x in range(100)])
table.append_row(list(["Name" for x in range(100)]))
print(table)
Become to:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na | Na |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
import enum
beautifultable/enums.py
enum exists only in Python 3.4 and onwards. If you want to support versions below (2.7 too) you have to add enum34 to your requires for the specific versions.
The printed table is misaligned when using colored data via module Blessings.
Here is an example.
from beautifultable import BeautifulTable
import blessings
term = blessings.Terminal()
table = BeautifulTable(max_width=120)
table.column_headers = [term.green('Header A'), term.cyan('Header B')]
table.append_row([term.yellow('data'), term.cyan('data')])
print(table)
Tested on:
Hi there - thank you for a great product.
I have table of data that is formatted just perfectly HOWEVER I do NOT want the column headers to be printed.
Is there a way I can stop the column headers from being printed.
Thank you very much
PJ
In e4d41c2 , ability to handle newline character was added. Hence with proper max_widths, another table could be in a cell of parent table. Logic could be added to adjust the max_width to ensure internal tables are not wrapped or stripped.
I tried to use the library colored to add colors to table elements, but when printing, the formatting was rendered to plain text. I just now saw that Style_NONE was applied. Is the problem due to this command? how can i turn it to manual?
Whenever I use column_widths
to change this parameter for a column and then run print(table)
, it resets the column's width back to the previous value.
So I have to use print(table.get_string(recalculate_width=False))
instead of the simple print statement.
Tutorial hasn't been updated in a while. The following could be included in it:
\n
)We should handle ANSI escape sequences so that the table isn't messed up when using colored output in the terminal.
First, thanks for the awesome tool! I'm just getting started with Python, so I'm not quite ready to figure out how to add this myself, but would it be possible to add a row_count method, similar to column_count?
Docs seems to update locally, but not on readthedocs. Currently we need to wipe the docs and rebuild but that is not Practical.
Hi,
First of all this is a great tool that im planning on using in my own project as a replacement for pandas dataframe. I love that you can index the elements inside a table unlike many other table packages.
However, everytime I print the a table to the console inside my own project I get the following warnings:
UserWarning: nperseg = 256 is greater than input length = 10, using nperseg = 10 .format(nperseg, input_length))
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name=1 mode='w' encoding='utf8'>
The first warning is a result of my own builtin function and I have successfully filtered out that warning but it always pops back up whenever I use your tool to print a table to the console. Warning number two only appears if I use your tool. I tried suppressing the warning by doing:
simplefilter('ignore', UserWarning)
simplefilter('ignore', ResourceWarning)
but it just wont go away. DO you have any suggestions on how to deal with this issue?
Hello! As I understand I can't update the column with iterator with len more than it is now in column.
And on table like this update by key is not work.
>>> print(table)
+------+
| year |
+------+
| 2013 |
+------+
| 2014 |
+------+
| 2015 |
+------+
| 2016 |
+------+
| 2017 |
+------+
| 2012 |
+------+
| 2011 |
>>> l_now = list(table['year'])
>>> l_now.extend(['2010', '2009, 2018'])
>>> table['year'] = l_now
>>> print(table)
'Here is the same table'
As I understand I must pop and after create new column?
from beautifultable import BeautifulTable
x = BeautifulTable()
x.append_row(["0", "a\nb"])
print(x)
+---+---+
| 0 | a |
| | b |
+---+---+
+---+-----+
| 0 | a
b |
+---+-----+
All separator fields are spelled as seperator. It's not a major issue but needs fixing. It is desirable that the fix is backcompatible.
I have an element I'm trying to add to my table and it's the string "2e77754" which is an ID number for something. This gets improperly recognized as a float with value 2x10^77754 and thus returns "inf" in my table instead of the string "2e77754".
I think the issue is in /beautifultable/utils/convert_to_numeric.py
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.