Python Cheat Sheet Github



A quick reference to Python

Cheat Sheet ¶ This part mainly focuses on common snippets in Python code. The cheat sheet not only includes basic Python features but also data structures and algorithms. Python cheat sheet - data structures¶A set of reference materials to help you in those occassional bouts of forgetfulness. Table of contents Play area Python tutorials and references Data structures. If you got certificate (like AWS), for the ssh you need to add your private key (.pem file) in the command. Ssh -i key.pem user@ipaddress. Ssh -i key.pem user@ipaddress -N -f -L localhost:8002:localhost:8002 user@ipadress. Next on the local machine run ssh tunneling.

Created on: 2019-09-29

Beginners python cheat sheet - github

Tag: cheat_sheet

Warning

under heavy construction and not well organized

(source: http://stackoverflow.com/a/34863581/5350059)

OR:

source: https://stackoverflow.com/a/34964610

(source: http://stackoverflow.com/a/1557584/5350059)

(source: http://stackoverflow.com/a/42641792/5350059)

(source: http://stackoverflow.com/a/6797990/5350059)

don't forget to import os

(source: http://stackoverflow.com/a/1274465/5350059)

(source: http://stackoverflow.com/a/32508983/5350059)

(source: http://stackoverflow.com/a/31923407/5350059)

(source: http://stackoverflow.com/a/15824216/5350059)

(source: http://stackoverflow.com/a/39452138/5350059)

(source: http://stackoverflow.com/a/8384838/5350059)

(source: http://stackoverflow.com/q/7961499/5350059)

(source: http://stackoverflow.com/a/25710057/5350059)

(source: https://stackoverflow.com/a/983382)

Cheat

(source: https://stackoverflow.com/a/1051266/5350059)

(source: https://www.facebook.com/groups/pythonbd/permalink/1182034515231297/)

(source: https://stackoverflow.com/a/73673/5350059)

(source: https://www.geeksforgeeks.org/send-mail-attachment-gmail-account-using-python/)

to see the package install location:

(source: https://stackoverflow.com/a/45309460/5350059)

to build regex with variable or as string:

source: https://stackoverflow.com/a/6931070/5350059

to find all string that matches a regex:

source: https://stackoverflow.com/a/4697884/5350059

to repeat string:

example:

source: https://stackoverflow.com/a/17183278/5350059

OR

use this:

source: https://stackoverflow.com/a/43828469/5350059

to access command line arguments:

Note

sys.argv is a list where sys.argv[0] is the program name.

source: https://stackoverflow.com/a/4033743/5350059

to check if argument is empty:

source: https://stackoverflow.com/a/2194187/5350059

to check if a list is empty:

source: https://stackoverflow.com/a/53522/5350059

Beginners Python Cheat Sheet - Github

to get full path from file and directory name:

source: https://stackoverflow.com/a/7133204/5350059

to iterate over files in a directory:

source: https://stackoverflow.com/a/10378012/5350059

Django supports bash auto-completion. for this first download auto-completion script:

Modify bashrc to add auto-completion script:

Best Python Cheat Sheet Pdf

Reload latest bashrc:

source: http://www.indjango.com/ubuntu-django-bash-auto-completion/

to install package from inside python shell:

source: https://stackoverflow.com/a/57594338/5350059

to print bold text:

Basic Python Cheat Sheet

We can do more tricks:

source: https://stackoverflow.com/a/17303428/5350059

to get all object attributes of a object:

source: https://stackoverflow.com/a/6886507/5350059

to beautify JSON in Python:

source: https://stackoverflow.com/a/9105132/5350059

to create a django secret key with bash:

Kept also in the Bash Cheat Sheet as it is relevant.

source: How to generate a random string?

to read dictionary in pandas:

source: pandas.DataFrame.from_dict

to print a column in pandas:

Output:

source: Display/Print one column from a DataFrame of Series in Pandas

to see heading columns in pandas: Commodore n60.

source: pandas.DataFrame.head

to do a dot matrix of two numpy array:

Python Cheat Sheet Github

source: NumPy v1.17 Manual: numpy.dot

to convert character to integer:

to convert integer to character:

source: https://stackoverflow.com/a/704160/5350059

to check if string is upper case:

Python Cheat Sheet Pdf

source: https://stackoverflow.com/a/3669033/5350059

source: https://stackoverflow.com/a/21890604