Skip to content

Instantly share code, notes, and snippets.

@sveetch
Created September 25, 2023 01:11
Show Gist options
  • Save sveetch/574cbe2a5d00d2e55f1233eae54b9954 to your computer and use it in GitHub Desktop.
Save sveetch/574cbe2a5d00d2e55f1233eae54b9954 to your computer and use it in GitHub Desktop.
A simple reminder quickcheat about Python encoding and decoding with string and bytes
In Python 3, this mental model is pretty straight-forward:
Encoding is the process of converting a str to a bytes object
Decoding is the process of converting a bytes object to a str
┏━━━━━━━┓ ┏━━━━━━━┓
┃ ┃ -> encoding -> ┃ ┃
┃ str ┃ ┃ bytes ┃
┃ ┃ <- decoding <- ┃ ┃
┗━━━━━━━┛ ┗━━━━━━━┛
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment