Python Forum
How is space of variables/functions/objects... called?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How is space of variables/functions/objects... called?
#1
Hello,
When you run a Python session, it stores all the variables you declare, and functions, objects... and you can access them at any time. Once you exit this Python session, and run a new one, all that was declared before will be gone.
I would like to know, how is this "session" called? Or is it a workspace? Or maybe scope? I tried to find it out online but honestly, I didn't even know how to search properly =/ Thank you, JC
Reply
#2
I guess it would be namespace
Python Docs Wrote:A namespace is a mapping from names to objects. Most namespaces are currently implemented as Python dictionaries, but that’s normally not noticeable in any way (except for performance), and it may change in the future. Examples of namespaces are: the set of built-in names (containing functions such as abs(), and built-in exception names); the global names in a module; and the local names in a function invocation. In a sense the set of attributes of an object also form a namespace. The important thing to know about namespaces is that there is absolutely no relation between names in different namespaces; for instance, two different modules may both define a function maximize without confusion — users of the modules must prefix it with the module name.
Reply
#3
Uh, thanks but I'm not sure about this... namespace seems more like, for example, difference between math.sin() and my_module.sin().
Reply
#4
Those are examples of namespaces, but what you were asking about is a special namespace as well. Just continue reading:

Quote:Namespaces are created at different moments and have different lifetimes. The namespace containing the built-in names is created when the Python interpreter starts up, and is never deleted. The global namespace for a module is created when the module definition is read in; normally, module namespaces also last until the interpreter quits. The statements executed by the top-level invocation of the interpreter, either read from a script file or interactively, are considered part of a module called __main__, so they have their own global namespace. (The built-in names actually also live in a module; this is called builtins.)
Reply
#5
Ah, alright, it seems like this is what I was looking for =) Apologies for the confusion and thanks a lot for clearing it up for me!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple variable inputs when only one is called for ChrisDall 2 449 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  Couldn't install a go-game called dlgo Nomamesse 14 2,977 Jan-05-2023, 06:38 PM
Last Post: Nomamesse
  how can a function find the name by which it is called? Skaperen 18 3,322 Aug-24-2022, 04:52 PM
Last Post: Skaperen
  using variables with functions imported from different files. Scordomaniac 3 1,220 May-24-2022, 10:53 AM
Last Post: deanhystad
  function with 'self' input parameter errors out with and without 'self' called dford 12 2,995 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  Storing whole functions in variables dedesssse 3 2,052 Jul-29-2021, 09:17 PM
Last Post: deanhystad
  Getting parent variables in nested functions wallgraffiti 1 2,099 Jan-30-2021, 03:53 PM
Last Post: buran
  What is this formatting called? Mark17 2 1,732 Dec-14-2020, 08:42 PM
Last Post: snippsat
  from global space to local space Skaperen 4 2,269 Sep-08-2020, 04:59 PM
Last Post: Skaperen
  module to store functions/variables and how to call them? mstichler 3 2,343 Jun-03-2020, 06:49 PM
Last Post: mstichler

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020