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

Why Don't Tuples Get The Same Id When Assigned The Same Values?

When I executed the following steps, both tuples (a and b) haven't retained their original IDs … Read more Why Don't Tuples Get The Same Id When Assigned The Same Values?

Python 3.4 Multiprocessing Queue Faster Than Pipe, Unexpected

I am doing an audio player that received samples from an udp socket, and everything was working fin… Read more Python 3.4 Multiprocessing Queue Faster Than Pipe, Unexpected

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

Memory Size Of List Python

I was experimenting something with lists and I came around self-referencing lists. I searched throu… Read more Memory Size Of List Python

What Is The Default Binding To The `__import__` Attribute Of The Module `builtin`?

From Python in a Nutshell Custom Importers An advanced, rarely needed functionality that Python of… Read more What Is The Default Binding To The `__import__` Attribute Of The Module `builtin`?

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

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

How Does __slots__ Avoid A Dictionary Lookup?

I've heard that __slots__ makes objects faster by avoiding a dictionary lookup. My confusion co… Read more How Does __slots__ Avoid A Dictionary Lookup?

How Does Cpython Determine Whether A User Supplied An Optional Argument?

I started wondering how CPython can tell the difference between None as a default argument and None… Read more How Does Cpython Determine Whether A User Supplied An Optional Argument?

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

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 Tuple(set([1,"a","b","c","z","f"])) == Tuple(set(["a","b","c","z","f",1])) 85% Of The Time With Hash Randomization Enabled?

Given Zero Piraeus' answer to another question, we have that x = tuple(set([1, 'a', … Read more Why Does Tuple(set([1,"a","b","c","z","f"])) == Tuple(set(["a","b","c","z","f",1])) 85% Of The Time With Hash Randomization Enabled?

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

Python 3 Integer Addresses

x=300 y=300 print(id(x),id(y)) a=[300,300] print(id(a[0]),id(a[1])) On executing above code I get … Read more Python 3 Integer Addresses

Making An Object X Such That "x In [x]" Returns False

If we make a pathological potato like this: >>> class Potato: ... def __eq__(self, oth… Read more Making An Object X Such That "x In [x]" Returns False

Why Doesn't The Namedtuple Module Use A Metaclass To Create Nt Class Objects?

I spent some time investigating the collections.namedtuple module a few weeks ago. The module uses … Read more Why Doesn't The Namedtuple Module Use A Metaclass To Create Nt Class Objects?

Python 3.4 Multiprocessing Queue Faster Than Pipe, Unexpected

I am doing an audio player that received samples from an udp socket, and everything was working fin… Read more Python 3.4 Multiprocessing Queue Faster Than Pipe, Unexpected

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

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

What Does "del" Do Exactly?

Here is my code: from memory_profiler import profile @profile def mess_with_memory(): huge_lis… Read more What Does "del" Do Exactly?