🖥️python

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the python command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

#                ██████╗ ██╗   ██╗████████╗██╗  ██╗ ██████╗ ███╗   ██╗
#                ██╔══██╗╚██╗ ██╔╝╚══██╔══╝██║  ██║██╔═══██╗████╗  ██║
#                ██████╔╝ ╚████╔╝    ██║   ███████║██║   ██║██╔██╗ ██║
#                ██╔═══╝   ╚██╔╝     ██║   ██╔══██║██║   ██║██║╚██╗██║
#                ██║        ██║      ██║   ██║  ██║╚██████╔╝██║ ╚████║
#                ╚═╝        ╚═╝      ╚═╝   ╚═╝  ╚═╝ ╚═════╝ ╚═╝  ╚═══╝
                

                                                                    
# Desc: Python is a high-level programming language.
# and python is a Python interpreter.

# Basic example of server with python
# Will start a Web Server in the current directory on port 8000
# go to http://127.0.0.1:8000

# Python v2.7
python -m SimpleHTTPServer
# Python 3
python -m http.server 8000

# SMTP-Server for debugging, messages will be discarded, and printed on stdout.
python -m smtpd -n -c DebuggingServer localhost:1025

# Pretty print a json
python -mjson.tool

python -m SimpleHTTPServer 
# Start a web server on port 8000 that uses CWD. See http://bit.ly/CLIhttpd  for other language examples. The command generates a simple web page over HTTP for the directory structure tree and can be accessed at port 8000 in browser till interrupt signal is sent.

python -c "for path in '%CLASSPATH%'.split(';'): print path"
# Use Python to print all the variable names on one line - note this can futz up some pathnames

python -c "import csv,json;print json.dumps(list(csv.reader(open('csv_file.csv'))))"
# Convert CSV to JSON - Replace 'csv_file.csv' with your filename.

echo "$(python -V 2>&1)" > file
or 
python -V 2> file
# Python version to a file
# This command sent the Python version to a file. This is intended to be used in scripts. For some reason, simple redirections didn't work with "python -V" This is sample output 
	cat file
	Python 2.6.3

# Zen of Python
# or just 'import this' in python
python -mthis

# See also:
#   Python language cheat sheets at /python/
#   list of pages:      /python/:list
#   learn python:       /python/:learn
#   search in pages:    /python/~keyword

# Get load average in a more parse-able format
python -c 'import os; print os.getloadavg()[0]'
# Explanation: In short, it runs a Python one-line script which imports the 'os' module and uses it to get the load average. It then indexes into a tuple, using the index of zero. The tuple is like this: (one-minute-average, five-minute-average, fifteen-minute-average), so you could substitute 0 for 1 to get the five minute load average, or 2 to get the fifteen minute load average. I find this really useful when writing larger bash one-liners which require this information, as I do not have to parse the output of uptime.
# Limitations: Requires Python.

# Random 6-digit number
python -c 'import random; print(random.randint(0,1000000-1))'
# Explanation: Stackoverflow has a dozen different ways to generate numbers, all of which fall apart after 3-4 digits. This solution requires Python to be installed, but is simple and direct.
# Limitations: Requires Python, it's not a pure-Bash solution

python -m ensurepip --default-pip && python -m pip install --upgrade pip setuptools wheel
# Bootstrap python-pip & setuptools

#==============================##==============================#
# CMD PYTHON						       #
#==============================##==============================#
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░