python -m json.tool
will format a string
$ cat data/example.json
[{"fieldname0": "User", "fieldname1": "Country", "fieldname2": "Age"}, {"fieldname0": "Alex", "fieldname1": "US", "fieldname2": "25"}, {"fieldname0": "Ben", "fieldname1": "US", "fieldname2": "24"}, {"fieldname0": "Dennis", "fieldname1": "UK", "fieldname2": "25"}, {"fieldname0": "Yuvi", "fieldname1": "IN", "fieldname2": "24"}](django-admin-cookbook)
$ cat data/example.json | python -m json.tool
[
{
"fieldname0": "User",
"fieldname1": "Country",
"fieldname2": "Age"
},
{
"fieldname0": "Alex",
"fieldname1": "US",
"fieldname2": "25"
},
{
"fieldname0": "Ben",
"fieldname1": "US",
"fieldname2": "24"
},
{
"fieldname0": "Dennis",
"fieldname1": "UK",
"fieldname2": "25"
},
{
"fieldname0": "Yuvi",
"fieldname1": "IN",
"fieldname2": "24"
}
]
python -m http.server
will start a server on port 8000 which will server the files from current dir.
$ python -m http.server 8844
Serving HTTP on 0.0.0.0 port 8844 (http://0.0.0.0:8844/) ...
Every python install comes with the idle editor, you can start it like this python -m idlelib.idle
$ python -m smtpd -n -c DebuggingServer localhost:1025
$ python -m cProfile scriptname.py
$ python -m venv venv_name
Assuming you have my_functions.py with next content:
def is_palindrome(text):
"""
Check if input text is palindrome
>>> is_palindrome('eye')
True
>>> is_palindrome('tree')
False
"""
return text == text[::-1]
To run doctests:
$ python -m doctest my_functions.py
python -m site
This prints
sys.path = [
'/Users/shabda/repos/cats/data',
'/Users/shabda/.virtualenvs/cats-may/lib/python36.zip',
'/Users/shabda/.virtualenvs/cats-may/lib/python3.6',
'/Users/shabda/.virtualenvs/cats-may/lib/python3.6/lib-dynload',
'/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
'/Users/shabda/.virtualenvs/cats-may/lib/python3.6/site-packages',
]
USER_BASE: '/Users/shabda/.local' (exists)
USER_SITE: '/Users/shabda/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: False