Wilson Mar bio photo

Wilson Mar

Hello. Join me!

Email me Calendar Skype call 310 320-7878

LinkedIn Twitter Gitter Google+ Youtube

Github Stackoverflow Pinterest

Tricks and tips


Overview

Here are various coding tips I’ve seen while going through Python programming classes after installing Python and Juypter.

Also see Python REST API programming. Python Robot testing. Running Python on Raspberry Pi IoT devices.

TODO: Move more here.

Command generator

docopt at https://github.com/docopt/docopt and described at http://docopt.org/ creates custom CLI commands by parsing a command help text into cli code that implements it.

Brilliant.

Click

Dan Bader recommends the use of the

http://click.pocoo.org/6/why/ click custom package (from Armin Ronacher) instead of the argparse package that comes with Python 3.2+ (and the optparse package that comes with Python 2).

Click provides decorators such as the “@click.command()” below:

\# cli.py
import click

@click.command()
def main():
    print("I'm a beautiful CLI ✨")

if __name__ == "__main__":
    main()
   

List comprehension

squares = [x * x for x in range(10)]

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]