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

In Python, What Is The Difference Between F.readlines() And List(f)

From both Python2 Tutorial and Python3 Tutorial, there is a line in the midpoint of section 7.2.1 s… Read more In Python, What Is The Difference Between F.readlines() And List(f)

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

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?

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?

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

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`?

In Python 3.x, Why Is There Not An Itertools Shared-object On Disk?

Is the itertools C module included somehow in the main Python binary in 3.x? Assuming that the C m… Read more In Python 3.x, Why Is There Not An Itertools Shared-object On Disk?

Why Does Genexp(generator Expression) Is Called Genexp? Not Iterexp?

A generator is a special kind of iterator, and it has some methods that an normal iterator doesn… Read more Why Does Genexp(generator Expression) Is Called Genexp? Not Iterexp?

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?

What Makes Lists Unhashable?

So lists are unhashable: >>> { [1,2]:3 } TypeError: unhashable type: 'list' The f… Read more What Makes Lists Unhashable?

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?

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?

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

Causes For Inconsistent Behavior When Adding Nans To A Set

There is puzzling (at least for me) behavior of Python's set in combination with NaNs (here liv… Read more Causes For Inconsistent Behavior When Adding Nans To A Set

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

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

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

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?

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?