Skip to content

Instantly share code, notes, and snippets.

@MrSnyder
Last active October 30, 2020 16:25
Show Gist options
  • Save MrSnyder/735cd03affde7694b6f5be3d33c6c55e to your computer and use it in GitHub Desktop.
Save MrSnyder/735cd03affde7694b6f5be3d33c6c55e to your computer and use it in GitHub Desktop.
Python Cheatsheet

Python Cheatsheet

Language

# list comprehension
names = ['Apple', 'Banana', 'wtf']
names_length = [len(v) for v in a]
name_to_length = {v:len(v) for v in a if len(v) < 4}

Dependency management

  • pip
  • requirements.txt

Virtual Env

# create venv
virtualenv -p python2.7 munimap

Misc

Django

SQL migration

# create SQL scripts for table creation / migration
python manage.py makemigrations <app>
# show SQL migration script 0001
python manage.py sqlmigrate <app> 0001
# apply SQL migration scripts
python manage.py migrate

Misc

# invoke shell
python manage.py shell
# create user for admin site
python manage.py createsuperuser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment