thefekete.net

$> :(){ :|:& };:

Bash: Count Lines of Code in a Python Project

#!/bin/bash
find . -name '*.py' | xargs cat | sed '/^\s*#/d;/^\s*$/d' | wc -l

xargs converts find’s output to arguments, the sed RE drops comments and blank lines, and wc counts them lines. Thanks to these posts on stack overflow for some reference material.

Quickly check line character maximums from the command line

If you want to make sure you didn’t go over 79 or 80 characters in a file you can simply run:

#!/bin/bash
grep -Pn '.{80,}' file-to-check

This uses grep’s perl regex option (-P) so we can use the expression .{80,} to find any lines that have >= 80 characters. The -n option prints the line numbers in the output so you can find them easily.

How to use *args and **kwargs in Python

The SaltyCrane Blog has a great post on the use of *args and **kwargs in python functions. Very simple and a good reference. You can check it out here:

http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/