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
• 9,460 points
12 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 5,950 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,710 points
947 views
+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,710 points
114 views
+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
2,480 views
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
70 views
0 votes
1 answer

How to hide a window in the constructor immediately after creation?

You can use QtCore.QTimer class Example(QWidget):     def __init__(self, app):         QWidget.__init__(self)         QTimer.singleShot(0, ...READ MORE

answered Apr 17, 2018 in Python by anonymous
16 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
20 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.