
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to make unique objects accessible in other modules of Python?
This is basically the idea of a singleton object. So if you have instantiated an obect and want to access it across different module, you can use 2 approaches, first being you assign that variable to the module you imported under a variable name. For example, you have a object myobj instantiated and want to use it with module B, then you can do the following:
>>> import B >>> B.myobj = myobj
And inside module B, use it like any other global property. Another way is to accept this object as a parameter wherever required. For example, if you have a function myfunc in module B that requires this object, you can do the following,
>>> import B >>> B.myfunc(myobj)
- Related Articles
- How to prohibit a Python module from calling other modules?
- How do we make planes and other flying objects?
- How to check version of python modules?
- Program to make file names unique using Python
- How to make a pair of columns unique in MySQL?
- How to make a unique field in MongoDB?
- How to install Python modules in Cygwin?
- How to use remote python modules?
- How to make an existing field Unique in MySQL?
- How to access Python objects within objects in Python?
- How to deploy python modules on Heroku?
- Program to count minimum deletions needed to make character frequencies unique in Python
- Extract unique objects by attribute from an array of objects in JavaScript
- How do Python modules work?
- How to encapsulate Python modules in a single file?

Advertisements