Fix Python – Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1?

Why does Python 3 allow “00” as a literal for 0 but not allow “01” as a literal for 1? Is there a good reason? This inconsistency baffles me. (And we’re talking about Python 3, which purposely broke backward compatibility in order to achieve goals like consistency.)
For example:
>>> from datetime import time
>>> time(16, 00)
datetime.time(16, 0)
>….

Fix Python – Why is str.translate much faster in Python 3.5 compared to Python 3.4?

I was trying to remove unwanted characters from a given string using text.translate() in Python 3.4.
The minimal code is:
import sys
s = ‘abcde12345@#@$#%$’
mapper = dict.fromkeys(i for i in range(sys.maxunicode) if chr(i) in ‘@#$’)
print(s.translate(mapper))

It works as expected. However the same program when executed in Python 3.4 and Python 3….

Fix Python – How can I make a python dataclass hashable?

Say a I have a dataclass in python3. I want to be able to hash and order these objects.
I only want them ordered/hashed on id.
I see in the docs that I can just implement _hash_ and all that but I’d like to get datacalsses to do the work for me because they are intended to handle this.
from dataclasses import dataclass, field

@dataclass(eq=True, ….

Fix Python – How to properly use the “choices” field option in Django

I’m reading the tutorial here: https://docs.djangoproject.com/en/1.5/ref/models/fields/#choices
and i’m trying to create a box where the user can select the month he was born in. What I tried was
MONTH_CHOICES = (
(JANUARY, “January”),
(FEBRUARY, “February”),
(MARCH, “March”),
….
(DECEMBER, “December”),
)

month = CharField(….

Fix Python – What is this odd colon behavior doing?

I am using Python 3.6.1, and I have come across something very strange. I had a simple dictionary assignment typo that took me a long time to find.
context = {}
context[“a”]: 2
print(context)

Output
{}

What is the code context[“a”]: 2 doing? It doesn’t raise a SyntaxError when it should IMO. At first I thought it was creating a slice. However, t….

Fix Python – What are variable annotations?

Python 3.6 is about to be released. PEP 494 — Python 3.6 Release Schedule mentions the end of December, so I went through What’s New in Python 3.6 to see they mention the variable annotations:

PEP 484 introduced standard for type annotations of function parameters, a.k.a. type hints. This PEP adds syntax to Python for annotating the types of var….

Fix Python – If range() is a generator in Python 3.3, why can I not call next() on a range?

Perhaps I’ve fallen victim to misinformation on the web, but I think it’s more likely just that I’ve misunderstood something. Based on what I’ve learned so far, range() is a generator, and generators can be used as iterators. However, this code:
myrange = range(10)
print(next(myrange))

gives me this error:
TypeError: ‘range’ object is not an it….

Fix Python – Understanding lambda in python and using it to pass multiple arguments

After reading everything I can find on lambda, I still don’t understand how to make it do what I want.
Everyone uses the example:
lambda x, y : x + y

Why do you need to state both x and y before the 😕 Also how do you make it return multiple arguments?
for example:
self.buttonAdd_1 = Button(self, text=’+’, command=lambda : self.calculate(self.bu….