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 0.0.0.0 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

Comments

Wool Blazers Shoes For Men and women

Three underutilized python commands - Agiliq Blog | Django web app development

commmenttor
The Way to Understand Imitation Sunglasses

Three underutilized python commands - Agiliq Blog | Django web app development

commmenttor
Post a comment Name :

Email :

Your site url:

Comment :

© Agiliq, 2009-2012