0

I have a python file main.py which is the driver of my GUI program and a folder games both inside the same folder. I want to refer the driver function in a file games\TicTacToe.py which is declared in main.py. How can I do it?

Here is my file structure

Project
|-games
|   |-TicTacToe.py
|   |-Snake_Game.py
|-main.py

2 Answers 2

1

You can use sys.path.insert(1, os.path.join(sys.path[0], '..')) to be able to access functions in the script from the parent directory. Then you can do import main

Sign up to request clarification or add additional context in comments.

Comments

1

If it works for you move the main.py to the games folder then put this at the start of the code: import main and every time you need to use one of its functions do main.functionName()

or if you only need to use one function then do this code: from main import FunctionName then when you use it you can dothis: FunctionName()

1 Comment

So the only viable option is to change the structure of the file?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.