Skip to content Skip to sidebar Skip to footer
Showing posts with the label Python Internals

Why Is It Slower To Iterate Over A Small String Than A Small List?

I was playing around with timeit and noticed that doing a simple list comprehension over a small st… Read more Why Is It Slower To Iterate Over A Small String Than A Small List?

Python 2 Assumes Different Source Code Encodings

I noticed that without source code encoding declaration, the Python 2 interpreter assumes the sourc… Read more Python 2 Assumes Different Source Code Encodings

In-place Custom Object Unpacking Different Behavior With __getitem__ Python 3.5 Vs Python 3.6

a follow-up question on this question: i ran the code below on python 3.5 and python 3.6 - with ver… Read more In-place Custom Object Unpacking Different Behavior With __getitem__ Python 3.5 Vs Python 3.6

Is An Explicit Nul-byte Necessary At The End Of A Bytearray For Cython To Be Able To Convert It To A Null-terminated C-string

When converting a bytearray-object (or a bytes-object for that matter) to a C-string, the cython-do… Read more Is An Explicit Nul-byte Necessary At The End Of A Bytearray For Cython To Be Able To Convert It To A Null-terminated C-string

When To Use `<>` And `!=` Operators?

Couldn't find much on this. Trying to compare 2 values, but they can't be equal. In my case… Read more When To Use `<>` And `!=` Operators?

Fraction Object Doesn't Have __int__ But Int(fraction(...)) Still Works

In Python, when you have an object you can convert it to an integer using the int function. For ex… Read more Fraction Object Doesn't Have __int__ But Int(fraction(...)) Still Works

Python: Which Types Support Weak References?

Code: from weakref import WeakSet se = WeakSet() se.add(1) Output: TypeError: cannot create weak r… Read more Python: Which Types Support Weak References?

Writing (and Not) To Global Variable In Python

Coming from much less dynamic C++, I have some trouble understanding the behaviour of this Python (… Read more Writing (and Not) To Global Variable In Python

How To Create A Custom Generator Class That Is Correctly Garbage Collected

I'm trying to write a class in Python that behaves as a generator object, particularly in that … Read more How To Create A Custom Generator Class That Is Correctly Garbage Collected

How To Call Parent Class Init With Default Values From Child Class?

I am trying to give my subclasses default variables and stop duplicating code as the file is gettin… Read more How To Call Parent Class Init With Default Values From Child Class?

Efficiency Of Sorting By Multiple Keys In Python

I have a list of strings that I want to sort by two custom key functions in Python 3.6. Comparing t… Read more Efficiency Of Sorting By Multiple Keys In Python

Handling Map Function In Python2 & Python3

Recently i came across a question & confused with a possible solution, code part is // code p… Read more Handling Map Function In Python2 & Python3

Why Does + (plus) Can Concatenate Two Strings In Python?

I'm learning Learn Python the hard way. w = 'This is the left side of...' e = 'a st… Read more Why Does + (plus) Can Concatenate Two Strings In Python?

Printing Without Parentheses Varying Error Message Using Python 3

When I try to use print without parentheses on a simple name in Python 3.4 I get: >>> prin… Read more Printing Without Parentheses Varying Error Message Using Python 3