

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The globals(), locals() and reload() Functions in Python
The globals() and locals() functions can be used to return the names in the global and local namespaces depending on the location from where they are called.
If locals() is called from within a function, it will return all the names that can be accessed locally from that function.
If globals() is called from within a function, it will return all the names that can be accessed globally from that function.
The return type of both these functions is dictionary. Therefore, names can be extracted using the keys() function.
When the module is imported into a script, the code in the top-level portion of a module is executed only once.
Therefore, if you want to reexecute the top-level code in a module, you can use the reload() function. The reload() function imports a previously imported module again. The syntax of the reload() function is this −
reload(module_name)
Here, module_name is the name of the module you want to reload and not the string containing the module name. For example, to reload hello module, do the following −
reload(hello)
- Related Questions & Answers
- The Anonymous Functions in Python
- The time Module in Python
- The calendar Module in Python
- The return Statement in Python
- The import Statements in Python
- The Threading Module in Python
- The match Function in Python
- The search Function in Python
- Checking an array for palindromes - JavaScript
- C# Math.BigMul Method
- Recursive multiplication in array - JavaScript
- What is the difference between dir(), globals() and locals() functions in Python?
- Passing static methods as arguments in PHP
- Subtracting two numbers without using the (-) sign JavaScript
- Using XPATH to search text containing