Skip to content

Instantly share code, notes, and snippets.

@kunrenzhilu
kunrenzhilu / unicode.py
Created March 7, 2022 01:18
unicode handling in python
import io
import json
if __name__=="__main__":
df = spark.table("item_lastest").filter(
col("country") == "TW"
).select(
"itemid", "name"
)
#python2
@kunrenzhilu
kunrenzhilu / python_logging.py
Created March 2, 2022 03:03 — forked from suiluj/python_logging.py
python logging pretty print pformat indent width line break
import logging
import time
from pprint import pformat
# pretty print logs: https://stackoverflow.com/a/11093247/5628238
# pformat indent: https://stackoverflow.com/a/29469358/5628238
# (even needed when using %s string format): do not evaluate complex pformat when log level not printed: https://docs.python.org/3/library/logging.html#logging.Logger.isEnabledFor
# (wrong: complex variable string takes time nevertheless): https://reinout.vanrees.org/weblog/2015/06/05/logging-formatting.html
# https://stackoverflow.com/questions/13131400/logging-variable-data-with-new-format-string
# main script or module
@kunrenzhilu
kunrenzhilu / Unicode.md
Created May 21, 2018 09:36 — forked from gornostal/Unicode.md
Python 2.7. Unicode Errors Simply Explained

Python 2.7. Unicode Errors Simply Explained

I know I'm late with this article for about 5 years or so, but people are still using Python 2.x, so this subject is relevant I think.

Some facts first:

  • Unicode is an international encoding standard for use with different languages and scripts
  • In python-2.x, there are two types that deal with text.
    1. str is an 8-bit string.
  1. unicode is for strings of unicode code points.