I learned that all variables, function, namespace in global scope becomes a property of window
object offered from browser, which is accessible in Javascript through console. Is there any object similar to this in Python?
Asked
Active
Viewed 407 times
0

PuffedRiceCrackers
- 725
- 6
- 18
-
2you want to search the web for "Python global namespace". The tl;dr is that Python has [locals(), globals(), and vars()](https://stackoverflow.com/questions/7969949/whats-the-difference-between-globals-locals-and-vars) – Mike 'Pomax' Kamermans Jan 09 '20 at 01:50
-
This is quite a strange question, is it purely for the sake of learning? – AMC Jan 09 '20 at 03:04
-
@AMC Yeah, this question wasn't out of any practical need. – PuffedRiceCrackers Jan 09 '20 at 03:56
-
Python doesn't run in the browser. – Rob Jan 09 '20 at 12:04
1 Answers
1
globals()
returns a dictionary that contains all global variables, maybe similar to what you are looking for.
globals()
> {'__builtins__': ... }
type(globals())
> <class 'dict'>
You may also interested in
dir()
: list of scoped variableslocals()
:dictionary of local variables

Thành Chung Bùi
- 548
- 3
- 16