Whats the difference between namespaces and names?

2024/11/16 12:00:23

I'm assuming the namespace is the allotted place in memory in which the name is to be stored. Or are they the same thing?

Answer

A namespace is a theoretical space in which the link between names and objects are situated: that is what is called a mapping between the names and the objects.
Names are the identifiers written in a script.
Objects are structures of bits lying in the memory.
The data structure that implements this theoretical namespace is a dictionnary. "Implements" means that it is the object that holds this data in the bits of the memory.
But the objects that this dictionary references are not grouped all together in a delimited portion of the memory, they are lying everywhere in the memory, it's the role of the dictionary to know how to find any of them with just a name at start when a name is encountered by the interpreter.
That's why I wrote it is a theoretical space, though it has a concrete existence in the memory. It is theoretical because the fact that several objects disseminated at different places in the memory can be considered to belong to one namespace is the result of the under-the-hood functionning of the Python interpreter, that is to say its data model and its execution model

In fact, things are more complex, under the hood there is a symbol table in the game. But I'm not enough competent concerning the C implementation of Python to say more. And by the way, people rarely allude to the symbol table.

However, I hope that the above explanation will shed some light in your mind concerning the subject of namespace.

https://en.xdnf.cn/q/119198.html

Related Q&A

Finding a string in python and writing it in another file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 10 years ago.Improv…

Python error TypeError: function takes exactly 1 argument (5 given)

Traceback (most recent call last):File "wdd.py", line 164, in <module>file.write("temperature is ", temperature, "wet is ", humidity, "%\n") TypeError: fun…

Django session not available on two seperate requests

Description: In the django session docs it says:You can read it and write to request.session at any point in your view.But I cant access the session when making a second request to the same view: views…

Counting how many times there are blank lists in a list of list [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Generating a list of random permutations of another list

So, Im trying to tackle the TSP with a Genetic Algorithm. To do that I need to create a population pool. What I want to accomplish is to create a list of random permutations that will represent a popul…

How to hide location of image in django?

models.py class UserInfo(models.Model):UID = models.CharField(max_length=50, primary_key=True, default=datetime.now().strftime("%d%y%H%S%m%M")) # default=fullname = models.CharField(max_leng…

Extracting data from multiple files with python

Im trying to extract data from a directory with 12 .txt files. Each file contains 3 columns of data (X,Y,Z) that i want to extract. I want to collect all the data in one df(InforDF), but so far i only …

Python: Checking if string follows wikipedia link format

If I have a string named link, how would I go about checking to see if it follows the same format as a wikipedia URL? To clarify, wikipedia URLs (in this case) always begin with en.wikipedia.org/wiki/…

Create dictionary comprehension from list with condition syntax

Id like to create a dictionary using dictionary comprehension syntax.Note that list l contains tuples of strings and tuples with 1st element always a time stamp.This works:d = {} for entry in l:if entr…

How to find next empty cell on a specific column and write to it?

I want to find the next empty cell in a specific column and write to values that cell. Ive tried it using following method: for row in sheet[A{}:A{}.format(sheet.min_row,sheet.max_row)]:if row is None:…