Quick and easy SMTP server with Python
Answer:
You can start a Python SMTP server, with only a single command, without installing any additional software in modern Linux.
E.g.
sudo python -m smtpd -n -c DebuggingServer localhost:25
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Quick and easy SMTP server with Python
Answer:
You can start a Python SMTP server, with only a single command, without installing any additional software in modern Linux.
E.g.
sudo python -m smtpd -n -c DebuggingServer localhost:25
Convert string to integer in Python
Answer:
You can use the built-in int() type constructor, e.g.
int('123') == 123
Installing Python modules with easy_install
Answer:
Install Python modules cannot be easier with easy_install.
To use easy_install, you can use apt-get to install the "python-setuptools" package
# sudo apt-get install python-setuptools
Then you can use easy_install to install the module you want, e.g. pymongo
# sudo easy_install pymongo
How to perform syntax check for Python program
Answer:
Assume you have a simple Python script hello.py, you want to perform syntax check. You can use the following method
# python -c 'import hello'
Traceback (most recent call last):
File "", line 1, in
File "hello.py", line 1
echo "Hello, World!"
If there is any syntax error, it will prompt out to the screen.
Serve current directory using HTTP with a single command
Answer:
Sometimes, you want to share some files in a given directory in your Linux system to other people, you might consider setup a NFS, Samba, FTP or so.
However, the easiest method is to export the directory using HTTP, with the help of Python.
E.g.
# cd /data/
python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
Now people can access the web server at port 8000 of your system's IP address, to access the /data directory.