Uso específico del módulo de vista de línea de comandos de Python

Generalmente, si está en Windows y ha instalado el entorno de desarrollo integrado Pycharm, no existe tal problema (Ctrl + clic del mouse en el nombre del objeto, puede ver directamente el uso de funciones específicas). Tome el módulo de terceros prettytable como ejemplo:

import prettytable as pt

# 按行添加数据
tb = pt.PrettyTable()
tb.field_names = ["id", "name", "phone", "age", "sex", "description"]
tb.add_row([1, "zhangsan", "132****2889", 25.23, "M", "NoDesc"])
tb.add_row([3, "lisi",     "152****7873", 18, "F", "None"])
tb.add_row([5, "wangwu",   "136****2908", 25, "M", "Nothing"])
tb.add_row([10,"zhaoliu",  "138****5322", 15, "M", "Nothing"])

print(tb)
# 按列添加数据
create_time = ["2020-11-30 20:03:07", "2020-11-30 20:08:33", "2020-11-30 20:10:11", "2020-11-30 20:12:11"]
tb.add_column("create_time", create_time)
print(tb)


------------------------------------------------------------
# prettytable.py

...
class PrettyTable(object):

    def __init__(self, field_names=None, **kwargs):

        """Return a new PrettyTable instance

        Arguments:

        encoding - Unicode encoding scheme used to decode any encoded input
        field_names - list or tuple of field names
        fields - list or tuple of field names to include in displays
        start - index of first data row to include in output
        end - index of last data row to include in output PLUS ONE (list slice style)
        header - print a header showing field names (True or False)

...

También puede recordar de forma inteligente al módulo qué funciones se pueden llamar y los parámetros que se pueden configurar: 

¿Y si está en la línea de comandos? ¿Hay alguna forma de comprobarlo? (¡Por supuesto que los hay! No olvides la función de ayuda)

[root@master ~]# python3
Python 3.6.8 (default, Aug  7 2019, 17:28:10) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help('prettytable')

Help on package prettytable:

NAME
    prettytable

PACKAGE CONTENTS
    prettytable

CLASSES
    builtins.object
        prettytable.prettytable.PrettyTable
    html.parser.HTMLParser(_markupbase.ParserBase)
        prettytable.prettytable.TableHandler
    
    class PrettyTable(builtins.object)
     |  Methods defined here:
     |  
     |  __getattr__(self, name)
     |  
     |  __getitem__(self, index)
     |  
     |  __init__(self, field_names=None, **kwargs)
     |      Return a new PrettyTable instance
     |      
...
     |  add_row(self, row)
     |      Add a row to the table
     |      
     |      Arguments:
     |      
     |      row - row of data, should be a list with as many elements as the table
     |      has fields
     |  
     |  add_rows(self, rows)
     |      Add rows to the table
     |      
     |      Arguments:
     |      
     |      rows - rows of data, should be an iterable of lists, each list with as many
     |      elements as the table has fields
     |  
     |  clear(self)
     |      Delete all rows and field names from the table, maintaining nothing but
     |      styling options
     |  
     |  clear_rows(self)
     |      Delete all rows from the table but keep the current field names
     |  
...

 

Supongo que te gusta

Origin blog.csdn.net/TomorrowAndTuture/article/details/110497812
Recomendado
Clasificación