Learn Python

  • data-coding
  • learn
  • python
  • summer

Specific topics

  • How to Use Generators and yield in Python, together with yield from
  • Create pip-installable packagesCreate pip-installable packages
    General

    Packaging Python Projects
    How to Package Your Python Code
    Creating a pip installable package
    [[Understand semantic versioning]]
    Choose the right open-source licence


    Github

    Create your custom Python package that you can pip-install from your git repository


    Poetry

    Docs
    When using Typer
    How to Effortlessly Publish your Python Package to PyPI Using Poetry
    It also helps with setup via poetry init

  • Use virtual environments to develop Python codeUse virtual environments to develop Python code
    What

    I like to think of virtual environments as package bookshelves for each of my projects. If I’m working on a cooking project, there is no need for me to have a book on surfing.
    Creates special isolated environments where all the packages and versions you install only apply to that specific environment. It’s like a private island! — but for code.


    Why

    Having only the packages I need on my “bookshelf” eliminates all chances for me to possibly experience gross global installation an...

Running remotely

General tools

  • shillelagh
    • Making it easy to query APIs via SQL
  • pythonji
    • Write Python with emojis
  • Pyscript
    • Python in the browser – running directly on browser client through virtual machine
    • Has some limitations over standard Python
    • Slow but it's expected it will speed up

Data tools

Snippets

  • Find out available versions for pip package:
    pip install package==
    
  • Check the list of packages installed, incl. their versions:
    pip freeze
    
  • Remove all packages that include a certain word:
    pip list | grep "word" | cut -d ' ' -f1 | xargs sudo -H pip uninstall -y
    
  • Pretty JSON in JupyterLab: ```python import json from IPython.display import JSON

JSON(json.loads('{"map": 1}'))


- Remove accents:
```python
from unidecode import unidecode

def remove_accents(str):
   return unidecode(str)

def generate_password_simple(nbytes): # the password will be long 1.3x the size pw = secrets.token_urlsafe(nbytes) return pw

def generate_password_custom(length, added): chars = string.ascii_letters + string.digits specs = ".+-*/="

main = [secrets.choice(chars) for i in range(length - added)]
extra = [secrets.choice(specs) for i in range(added)]
final = main + extra
random.shuffle(final)

pw = ''.join(final)
return pw ```

Debugging

"Code does not do what you expect it to do, but what you tell it to do."

"The most effective debugging tool is still careful thought, coupled with judiciously placed print statements." – Brian Kernighan, Unix for Beginners

Metadata