I’m creating Hangman game using classes that are in separate files.
One of them (wordsHangman.py)is responsible for randomly selecting a word from text file, and it’s in a package “words_from_file”.
Later on I’m importing this module to another file containing class with the main game (hangman.py). However it’s in a different folder.
Please see visual explanation -> https://i.imgur.com/77e05b6.png
So far I tried with os module and adding
However it raises FileNotFoundError: [Errno 2] No such file or directory: ”
Currently I’m pointing path of package containing text file in wordsHangman.py in the following way :
file = open('words_from_file/words.txt', 'r')
init file in my words_from_file package contains :
from .wordsHangman import Words __all__ = ["Words"]
I’m importing wordsHangman module to hangman with :
from words_from_file import *
I would like to be able to import this module without ‘manually’ specifying file’s path (so if it will be moved to another package, my hangman module will still be able to import it).
How can I do this ?