Giter Site home page Giter Site logo

cprint's Introduction

cprint

Python function to print a list of items in a columnar format for easy reading.

Example Usage

>>> items = dir(str)
>>> cprint(items)
__add__             __mod__            find           maketrans   
__class__           __mul__            format         partition   
__contains__        __ne__             format_map     removeprefix
__delattr__         __new__            index          removesuffix
__dir__             __reduce__         isalnum        replace     
__doc__             __reduce_ex__      isalpha        rfind       
__eq__              __repr__           isascii        rindex      
__format__          __rmod__           isdecimal      rjust       
__ge__              __rmul__           isdigit        rpartition  
__getattribute__    __setattr__        isidentifier   rsplit      
__getitem__         __sizeof__         islower        rstrip      
__getnewargs__      __str__            isnumeric      split       
__gt__              __subclasshook__   isprintable    splitlines  
__hash__            capitalize         isspace        startswith  
__init__            casefold           istitle        strip       
__init_subclass__   center             isupper        swapcase    
__iter__            count              join           title       
__le__              encode             ljust          translate   
__len__             endswith           lower          upper       
__lt__              expandtabs         lstrip         zfill       

format_spec follows the Python String Format Mini-Language, with the exception that the character w stands in for the width specifier.

In this case, format_spec is set to align the columns right:

>>> cprint(items, columns=6, format_spec='{:>w}')
         __add__            __init__           __rmul__     format_map           join       rstrip
       __class__   __init_subclass__        __setattr__          index          ljust        split
    __contains__            __iter__         __sizeof__        isalnum          lower   splitlines
     __delattr__              __le__            __str__        isalpha         lstrip   startswith
         __dir__             __len__   __subclasshook__        isascii      maketrans        strip
         __doc__              __lt__         capitalize      isdecimal      partition     swapcase
          __eq__             __mod__           casefold        isdigit   removeprefix        title
      __format__             __mul__             center   isidentifier   removesuffix    translate
          __ge__              __ne__              count        islower        replace        upper
__getattribute__             __new__             encode      isnumeric          rfind        zfill
     __getitem__          __reduce__           endswith    isprintable         rindex
  __getnewargs__       __reduce_ex__         expandtabs        isspace          rjust
          __gt__            __repr__               find        istitle     rpartition
        __hash__            __rmod__             format        isupper         rsplit

cprint's People

Contributors

graxel avatar

Stargazers

 avatar

Watchers

 avatar

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.