Leo's Technical Blog

Python command line tricks

Introduction

user

Leo Soto


python, tips

Python command line tricks

Posted by Leo Soto on .
Featured

python, tips

Python command line tricks

Posted by Leo Soto on .

Here is a couple of useful tricks you can perform on any machine with Python installed.

1. Serve the current directory via HTTP

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

Quite useful for sharing files on a network when the usual file sharing systems fail and/or you don't want to mess with accounts/passwords just for transmitting a couple of files.

2. Create a debugging SMTP server

$ sudo python -m smtpd -n -c DebuggingServer localhost:25

If you need to test an application that sends emails but don't have an email server installed on your development machine, by running the Python's DebuggingServer you will have one. It won't deliver the incoming mails but will print them on the standard output so you can see if the application is sending the emails correctly and also inspect the content easily.