The card I gave myself today says “Read Python language docs until I have written down 10 new things.” Why? Somebody pointed out that var = val or '-' was cleaner than the mess I used instead, and I realized that much more effort is required. (Were it Perl, I’d probably have used or '-', but I can’t always keep the features of the different languages straight.)
Here’s today’s list, which includes some things I’m familiar with in Python or other languages but can’t pull out of a hat on demand.
- The file is UTF-8: # -*- coding: utf-8 -*- (or UTF-8 byte-order mark or VIM-style coding string)
- Identifiers named _* are not imported by from module import *. (I knew that a leading _ is for privacy but I didn’t realize it was enforced anywhere besides analysis tools. But I don’t think I use from module import * except with cascaded Django settings.)
- Identifiers named __* are class-private, and this is essentially enforced.
- Wow, combining string prefixes, as in ur or br, is new to me, as is using upper case string prefixes, such as R, bR, etc.
- I forgot about escape sequences for Bell, Backspace, Formfeed, and Vertical Tab, and never knew about \N{name-of-Unicode-character}. (I probably didn’t know about octal escape sequences in Python either.)
- I don’t always use whitespace to concatenate string literals, though I should where applicable.
- complex literals — 3.14j, 3.14e-10j
- ^ operator, for XOR
- the NotImplemented single-valued type, for returning from certain methods
- the Ellipses single-valued type, for indicating the presence of the ... syntax in a slice