Three underutilized python commands

By : Shabda Raaj

Today's post are three simple Python commands which should be known more widely, but are not.

Start a simple web server to serve files from current directory.

~$ python -m SimpleHTTPServer
Serving HTTP on port 8000 ...

This is neither secure, nor scalable, but handy if you are in a directory and want to quickly test something.

Testing emails

~$ python -m smtpd -n -c DebuggingServer

Starts a fake SMTP server on port 1025. Useful if you are testing emails on a system which doesn't allow pluggable emails backends.

Pretty print JSON

echo '{"2legs":"Better", "4Legs": "Good", "6Legs": "Spider"}' | python -m json.tool
  • Inspired by a tweet from Adrian Holovaty
  • The -m switch was added in PEP-338
  • Try these too python -m unittest discover ., python -m timeit -s 'import random; 10*random.randint(10, 20)'

Related Posts

Can we help you build amazing apps? Contact us today.

Topics : python tips Python
© Agiliq, 2009-2012