0

How to access an object created in another module using python

1

3 Answers 3

4
import other_module

other_module.some_object.do_something()
Sign up to request clarification or add additional context in comments.

Comments

3

Yeah,

Thats right,

from module import desired_object

module exapmle:

# Desired Module:

desired_object = None
def my_func():
    global desired_object
    desired_object = SomeObject()

But make sure the 'my_func' must be called before importing desired_object from your module

1 Comment

Is your code right if the desired_object was created inside a function?
3

Also you could do

from module import object
object.function()

1 Comment

Wow, a code listing consisting only of words SO considers reserved.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.