Python `-m`

Author: yifei / Created: May 30, 2017, 9:19 p.m. / Modified: May 30, 2017, 9:32 p.m. / Edit

How -m is invoked

if you have a module foo

write foo/

then python -m foo will execute

json pretty print

cat some_json_file | python -m json.tool

zipfile -l        # Show listing of a zipfile -t        # Test if a zipfile is valid -e target # Extract zipfile into target dir -c src ... # Create zipfile from sources


python -m gzip wordlist.txt  # Will create wordlist.txt.gz python -m gzip -d wordlist.txt.gz  # Will extract to wordlist.txt


compare two directories

$ python -m filecmp /tmp/a /tmp/b diff /tmp/a /tmp/b Only in /tmp/a : ['1'] Only in /tmp/b : ['2'] Identical files : ['4'] Differing files : ['3']

Several modules lets you encode/decode in various formats: • base64 • uu • encodings.rot_13 • binhex • mimify • quopri For example $ echo 'secertpassword' | python -m encodings.rot_13 frpregcnffjbeq


python -m SimpleHTTPServer # 2 python -m http.server #3

python -m pydoc {module/func}


python -m cProfile python -m timeit python -m pstats python -m trace