Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

readme.md

Python Day-To-Day Usefull Snippets

Note: here command or snippets are for python3, most the command might work in python2 and you might have to change few things to make it work in python2


Quickly find the python version

A very basic one but important part here to know is most of the command will have the same syntax to get the version details

python3 --version

Simplest Hello (without world)

Again a basic once, but this tells us that we can run a small python snippet just via the cli, without writing/creating a python file. a lot of other programming languages (basically their executables) also gives the same functionality

python -c "print('Hello')"

Get MD5 Hash

A quick way to get MD5 hash of a string

python3 -c "import hashlib; print(hashlib.md5(b'Ashish').hexdigest())"

same goes for sha512

python3 -c "import hashlib; print(hashlib.sha512(b'Ashish').hexdigest())"

A Simple Python3 HTTP Server (@ Port 80)

If you have a requirement of to transfer files (over http), this small cli based approach of python can help you quickly expose all the files (hierarchy with subfolder and files) of your CWD over http port (you can customize the port as per your requirement)

python3 -m http.server 80