I'm currently learning Python, and I tried importing my own modules but first I got AttributeErrors and then I got ImportErrors (after trying another importing method) and even after searching for 3 hours for a solution I couldn't find one. Restarting VS Code and the Terminal several times and restarting my pc didn't help either. I was about to post my question here and to make it easier to see I moved my 3 files to a new folder. Suddenly it worked without issues! Even after moving the files to the folder I got the errors from it still continued working. I didn't change anything besides moving the files.
Could someone explain why that happend and what caused the errors?
It was structured like this (Code simplified and shortend):
First (didn't work):
C:\Users[User-ID]\OneDrive\Dokumente\Code\Python\hman\hangman_art.py
C:\Users[User-ID]\OneDrive\Dokumente\Code\Python\hman\hangman_words.py
C:\Users[User-ID]\OneDrive\Dokumente\Code\Python\hman\hangman05.py
Second (worked):
C:\Users[User-ID]\Desktop\hangman_art.py
C:\Users[User-ID]\Desktop\hangman_words.py
C:\Users[User-ID]\Desktop\hangman05.py
Then first again (worked too)
hangman_words.py
word_list = [
'abruptly',
'absurd',
'axiom'
]
hangman_art.py
logo = '''
_
| |
| |__ __ _ _ __ __ _ _ __ ___ __ _ _ __
| '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \
| | | | (_| | | | | (_| | | | | | | (_| | | | |
|_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_|
__/ |
|___/ '''
hangman.py
import hangman_art
import hangman_words
print(hangman_art.logo)
print(hangman_words.word_list)
# Resutlted first in AttributeErrors:
AttributeError: module 'hangman_art' has no attribute 'logo' in Python
# Later in IndexErrors after I tried (from hangman_art import logo):
ImportError: cannot import name 'logo' from 'hangman_art'