Identifier normalization: Why is the micro sign converted into the Greek letter mu?

There are two different characters involved here. One is the MICRO SIGN, which is the one on the keyboard, and the other is GREEK SMALL LETTER MU. To understand what’s going on, we should take a look at how Python defines identifiers in the language reference: identifier ::= xid_start xid_continue* id_start ::= <all characters in … Read more

How to run CGI “hello world” with python http.server

From the http.server docs: CGIHTTPRequestHandler can be enabled in the command line by passing the –cgi option: $ python3 -m http.server –bind localhost –cgi 8000 Put your script into cgi_directories: This defaults to [‘/cgi-bin’, ‘/htbin’] and describes directories to treat as containing CGI scripts. Open in the browser: $ python -mwebbrowser http://localhost:8000/cgi-bin/hello.py where hello.py: #!/usr/bin/env … Read more

ImportError: Cannot load backend ‘TkAgg’ which requires the ‘tk’ interactive framework, as ‘headless’ is currently running

What solved the problem for me was to restart my kernel, import the following first: import matplotlib matplotlib.use(‘TKAgg’) Then, import matplotlib.pyplot as plt You probably imported matplotlib with another framework before you tried to change to TKAgg. Restart your kernel.

How to imitate Python 3’s raise … from in Python 2?

There’s a raise_from in python-future; simply install it pip install future and import to use from future.utils import raise_from # or: from six import reraise as raise_from class FileDatabase: def __init__(self, filename): try: self.file = open(filename) except IOError as exc: raise_from(DatabaseError(‘failed to open’), exc) UPDATE The compatibility package six also supports raise_from, from version 1.9 … Read more

Accessing dictionary items by position in Python 3.6+ efficiently

For an OrderedDict it’s inherently O(n) because the ordering is recorded in a linked list. For the builtin dict, there’s a vector (a contiguous array) rather than a linked list, but pretty much the same thing in the end: the vector contains a few kind of “dummies”, special internal values that mean “no key has … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)