Giter Site home page Giter Site logo

kxxoling / ptable Goto Github PK

View Code? Open in Web Editor NEW
129.0 8.0 44.0 259 KB

PrettyTable is a simple Python library designed to make it quick and easy to represent tabular data in visually appealing ASCII tables.

Home Page: https://pypi.python.org/pypi/ptable

License: Other

Makefile 0.96% Python 99.04%

ptable's Introduction

About PTable

PTable is a simple Python library designed to make it quick and easy to represent tabular data in visually appealing ASCII tables, originally forked from PrettyTable.

Build Status Code Health Coverage

Installation

As PTable is a fork of PrettyTable, and compatible with all its APIs, so PTable is usage is the same as PrettyTable, and the installation would cover on the original PrettyTable.

As always, you can install PTable in 3 ways.

Via pip (recommend):

pip install PTable

Via easy_install:

easy_install PTable

From source:

python setup.py install

Quick start

PTable supports two kinds of usage:

As a library

PTable library API is almost as PrettyTable, you can import the same API from prettytable library:

from prettytable import PrettyTable
x = PrettyTable()

A better hosted document is hosted on ReadTheDocument.

As command-line tool

This is an original function of PTable, can be used as ptable command:

ptable --csv somefile.csv

or a Unix style pipe:

cat somefile.csv | ptable

Will both print a ASCII table in terminal.

Relative links

ptable's People

Contributors

hugovk avatar kadler avatar kxxoling avatar luky1971 avatar sebelino avatar sewci0 avatar svetlyak40wt avatar wolfhong avatar zarnovican avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ptable's Issues

Maintenance

Is this project being maintained?
All the pull requests are about a year old.

Rows added where field has `\n` adds multiple rows

I am experiencing a problem where adding a row that has strings with \n in them will produce more rows in the table.

e.g.
Adding the following row:

[u'change hostname', u'hostname', [], u'validator1', u'12345678', [], u'this is a text\n\n\n\n\n\n\n\n\n\n']

Produces a table with multiple lines:

+-----------------+--------------+------------+------------+------------+-----------+----------------+
|   description   | templateName | tenantList | validators | templateId | sitesList |    payload     |
+-----------------+--------------+------------+------------+------------+-----------+----------------+
| change hostname |   hostname   |     []     | validator1 |  12345678  |     []    | this is a text |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
|                 |              |            |            |            |           |                |
+-----------------+--------------+------------+------------+------------+-----------+----------------+

Deprecation warning due to invalid escape sequences in Python 3.8

Deprecation warnings are raised due to invalid escape sequences in Python 3.8 . Below is a log of the warnings raised during compiling all the python files. Using raw strings or escaping them will fix this issue.

find . -iname '*.py'  | xargs -P 4 -I{} python -Walways -m py_compile {}
./prettytable/prettytable.py:25: DeprecationWarning: invalid escape sequence \[
  _re = re.compile("\033\[[0-9;]*m")
./prettytable/prettytable.py:925: DeprecationWarning: invalid escape sequence \{
  self.vertical_char = random.choice("~!@#$%^&*()_+|-=\{}[];':\",./;<>?")
./prettytable/prettytable.py:926: DeprecationWarning: invalid escape sequence \{
  self.horizontal_char = random.choice("~!@#$%^&*()_+|-=\{}[];':\",./;<>?")
./prettytable/prettytable.py:927: DeprecationWarning: invalid escape sequence \{
  self.junction_char = random.choice("~!@#$%^&*()_+|-=\{}[];':\",./;<>?")
./prettytable/prettytable.py:424: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif val is None or (isinstance(val, dict) and len(val) is 0):
./prettytable/prettytable.py:444: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif val is None or (isinstance(val, dict) and len(val) is 0):
./prettytable/prettytable.py:462: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if val is None or (isinstance(val, dict) and len(val) is 0):
./prettytable/prettytable.py:492: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if val is None or (isinstance(val, dict) and len(val) is 0):
./prettytable/prettytable.py:690: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if val is None or (isinstance(val, dict) and len(val) is 0):
./prettytable/prettytable.py:707: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if val is None or (isinstance(val, dict) and len(val) is 0):

Pyinstaller compatibility, name of dist-info

When trying to package the application using pyinstaller it complains :
pkg_resources.DistributionNotFound: The 'prettytable' distribution was not found and is required by the application

In fact, the distribution is available in the directory envname/Lib/site-packages but it has not the expected name by pyinstaller

prettytable
PTable-0.9.2.dist-info

I have just copy and rename the directory PTable-0.9.2.dist-info to prettytable-0.9.2.dist-info

So now in the directory envname/Lib/site-packages , I have among other directories,

prettytable
prettytable-0.9.2.dist-info
PTable-0.9.2.dist-info

And it fix the pyinstaller problem.

Is it possible to not wrap text in some columns?

I've tried PTable for my command line client to AllMyChanges.com and that is what I've got:

+----------+--------------------------------+--------------+------------------------------------------------------------------+
| namespace |              name              |   version    |                           description                            |
+----------+--------------------------------+--------------+------------------------------------------------------------------+
| javascri |        angucomplete-alt        |    2.4.1     | Autocomplete Directive for AngularJS. A fork of Daryl Rowland's  |
|    pt    |                                |              |                         angucomplete (h…                         |
| javascri |    angular-bootstrap-switch    |    2.0.0     |   AngularJS directive for the bootstrap-switch jQuery plugin.    |
|    pt    |                                |              |                                                                  |
...

There are two problems:

  1. In first column, keyword javascript is wrapped. I'd like to wrap only description column which could be really lenthy.
  2. Header line is longer than screen width.

For this experiment, I used max_table_width argument. Which was get_terminal_width() - 2, where:

def get_terminal_width():
    rows, columns = os.popen('stty size', 'r').read().split()
    return int(columns)

Can’t install with pip

I get this error:

Could not install packages due to an EnvironmentError: 404 Client Error: Not Found for url: https:
//www.piwheels.org/simple/ptable/

Cannot add HTML attribute

I'm trying this example: x.print_html(attributes={"name":"my_table", "class":"red_table"}):

from prettytable            import PrettyTable
...
        self.log_rpt_comp_tbl = PrettyTable()
        self.log_rpt_comp_tbl.field_names = ["Testbench", "Defines", "Status", "Errors", "Warnings"]
        self.log_rpt_comp_tbl.align["Testbench"] = "l"
        self.log_rpt_comp_tbl.align["Defines"] = "l"
        self.log_rpt_comp_tbl.format = True
        self.log_rpt_comp_tbl.print_html(attributes={"name":"my_table", "class":"red_table"})

And get the following error:

Traceback (most recent call last):
  File "d:\scripts\regr_main.py", line 532, in <module>
    regr.main()
  File "d:\scripts\regr_main.py", line 96, in main
    self.log_rpt_comp_tbl.print_html(attributes={"name":"my_table", "class":"red_table"})
  File "C:\Program Files\Python36\lib\site-packages\prettytable\prettytable.py", line 192, in __getattr__
    raise AttributeError(name)
AttributeError: print_html

Wrap items in specific column with specified tag

One of the columns outputted in the table I'm building is a URL. I was wondering if there was a way to specify how a column is printed so it can be a clickable link. This example is given:

x.print_html(attributes={"name":"my_table", "class":"red_table"})
will print:

<table name="my_table" class="red_table">
    <tr>
        <th>City name</th>
        <th>Area</th>
        <th>Population</th>
        <th>google.com</th>
    </tr>
    ...
    ...
    ...
</table>

I would like it to be printed as:

<table name="my_table" class="red_table">
    <tr>
        <th>City name</th>
        <th>Area</th>
        <th>Population</th>
        <th><a href = google.com>google.com</a></th>
    </tr>
    ...
    ...
    ...
</table>

Is this possible? Thanks.

Add How PTable is different from Prettytable to readme

As an existing Prettytable user I need information as to why you forked it and, how you are different, new features, etc.

Please could you add this to the readme? It would help existing users like me to decide to switch.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.