-1

This is a confusing title, so I'll explain my situation here. I have 3 files:

file.py:

class me:
    def update(self):
        # Code to update something

main.py:

import file
import other # Because it uses some classes from other
obj = me()

other.py:

# From here I need to be able to run the update() function that is shown in file.py

So, as it says, in other.py I need to be able to run the update() function on the object of the me class (which is created in main.py)

  • 1
    Why do you think you need to do this? If you show us your actual use-case, we may be able to suggest alternative, more pythonic solutions. – Paul M. Apr 05 '21 at 12:26
  • I'll try but it is complicated. I am using tkinter, moviepy and am trying to implement a drag and drop. In my file.py I create a tkinter window (in a class) and have an update function which I call from within the same class. I need to call this from another file (other.py) which has a drag and drop manager for tkinter. This needs to update the main class. I hope this helps a bit – SomeoneLudo Apr 05 '21 at 12:35
  • If you want to see all the code it is [here](https://github.com/MiniMinnoww/moviepy-video-editor) – SomeoneLudo Apr 05 '21 at 12:37

1 Answers1

0

you can import the function with from file import update but I do not think that you can call the function on an object created in another file as long as you do not save this object and read it back.

If you really need to, you can save the object obj and then read it back in other.py. There are many great answers on this in the internet. For example: Saving an Object (Data persistence)

Berkay Berabi
  • 1,933
  • 1
  • 10
  • 26