
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
How do I create a Python namespace?
Each package, module, class, function and method function owns a "namespace" in which variable names are resolved. When a function, module or package is evaluated (that is, starts execution), a namespace is created. So if you want to create a namespace, you just need to call a function, instantiate an object, import a module or import a package. For example, we can create a class called Namespace and when you create an object of that class, you're basically creating a namespace.
Example
In this class, you can also pass variable names to attach to the namespace, for example,
class Namespace: def __init__(self, **kwargs): self.__dict__.update(kwargs) args = Namespace(a=1, b='c') print args.a, args.b
Output
This will give the output:
1 c
- Related Articles
- How do I create a namespace package in Python?
- How do I declare a namespace in JavaScript?
- How do I import all the submodules of a Python namespace package?
- How to create python namespace packages in Python 3?
- How do I create a multidimensional list in Python?
- How do I create a .pyc file in Python?
- How do I create a user interface through Python?
- Do recursive functions in Python create a new namespace each time the function calls itself?
- How do I create child windows with Python tkinter?
- How do I create documentation from doc strings in Python?
- How do I create a view in MySQL?
- How do I create a java.sql.Date object in Java?
- How do I create a popup window using Tkinter?
- How do I create a popup window in Tkinter?
- How do I create a date picker in tkinter?

Advertisements