Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

Import a python Class from another sub-directory of parent directory

$
0
0

So I'm trying to do some stuff with Json, and so I want to be able to acces the Dragoon Class (in Dragoon.py) from the Character_manager.py file.Here's what my folder looks like.

- Code    - Classes        - Arbalist        - Bard        - Character (every other class extends from this)        - Dragoon        - Guardian        - Seraph        - Slaughterer        - Spellcaster    - Data        -  Account_manager.py        - Accounts.json        - Character_manager.py        - Characters.json

So I tried using a couple of solutions found on the internet, but most of them where only working for either Python2 or to import from Parent Directory only.

If I forgot to specify anything, please let me know!

Edit:Some of you asked about what is the point of the code, so here is when I would use the dragoon import.

print("Choose a profession")print("1. Dragoon")choice = input("Choice: ")        match (choice):            case "1":                character = Dragoon()            case _:                character_manager(username) #Go back to the previous menu

Someone also suggested to regroup every Class into the Character.py file, which doesn't sound like a bad idea and it's probably what I will be doing (I'm used to have one class per file with Java).I'll then try to import the new Character.py as a whole, and shouldn't be a problem anymore. (I'll update/answer when done)

For my own culture, would anyone still be able to answer the first issue?


Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>