Game Code Python Import

DarkGizmo

  • Jr. Member
  • **
    • Posts: 8
    • View Profile
I've just received my Thumbies (!!!)
I wanted to import my game to it, but it doesn't run. I've been commenting code to figure out the issue and the first issue I see is importing game files.
I've split my code into multiple file and had no issue importing other files, but it seems I was running the files from the root, when I move my game to "/Games/Demo" instead of "/" my import don't work anymore

I've notice that if I change
"import game_framework" to "import Games.Demo.game_framework" it seems to fix the issue

But then when I want to change the name to something meaningful I'll have to go through all my files and swap the imports...

Is there some python code I don't know that might solve this issue?
Is there something I'm missing?
Or am is that simply a limitation of how the thumby/micropython works that I have to handle manually?


DarkGizmo

  • Jr. Member
  • **
    • Posts: 8
    • View Profile
For those interested here's the solution I found:

Add this to you main file (Your __YOUR_GAME__.py file)
Code: [Select]
# Add Current Folder to Path
current_working_directory = "/".join(__file__.split("/")[0:-1])
sys.path.insert(1, current_working_directory)

current_working_directory will be "/Games/__YOUR_GAME__"
By inserting in sys.path the import should work even if they are in the current directory and not in the root



 

SMF spam blocked by CleanTalk