Re-assigning a name to itself

0 votes
In the following lines of multiprocessing package of standard libraries:

dict = dict
list = list

What's the point of rebinding some names already available on __builtins__ into the module scope? What is it trying to achieve? I couldn't find a suitable and relevant explanation.
Oct 17, 2018 in Python by SDeb
• 13,160 points

1 answer to this question.

0 votes
This code occurs in multiprocessing.dummy, a "fake" version of multiprocessing that implements the functionality with threads. If you look down a few lines, you'll see

def Manager():
    return sys.modules[__name__]
multiprocessing.dummy implements Manager as a function that just returns the multiprocessing.dummy module itself, so the multiprocessing.dummy module object has to provide the API of a multiprocessing Manager object. The lines

dict = dict
list = list
copy the bindings for the dict and list names from the builtins namespace into the module's namespace, so you can do

m = multiprocessing.dummy.Manager()
d = m.dict()
as if you had a real multiprocessing.Manager()
answered Oct 17, 2018 by ana1504.k
• 7,870 points

Related Questions In Python

+2 votes
2 answers

How to make a laplacian pyramid using OpenCV python?

down voteacceptTheeThe problem is that you're iterating ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,720 points
+1 vote
2 answers

How to resize the image canvas to maintain a square aspect ratio

down voteacceptedUsing OpenCVYou can use resize() in OpenCV to ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
+1 vote
4 answers

How to write nested dictionaries to a CSV file

Using DictWriter there is no need in ...READ MORE

answered Oct 18, 2018 in Python by Richard William
0 votes
1 answer

How can I write nested dictionaries to a csv file?

You can use the pandas library to ...READ MORE

answered Apr 17, 2018 in Python by anonymous
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 232 views