Not sure how to access user's file in python

Question:
I am collaborating with someone and we are making a Pokémon game. We store the user’s data in files formatted something like this - user_PLYR.py. We’d like to import variables from the file to use for reference but I’m not sure how to access the user’s file.

Repl link:
Pokemon RPG Game - Replit

Some Code
The goal is to access the user (in this case, the user’s file is ADMIN_PLYR.py) but there is no way to write from {name}_PLYR import starter
I need help making it so that I can access the user’s PLYR file.

Would PLYR = __import__(f"{name}_PLYR") work for that?
And for starter: starter = __import__(f"{name}_PLYR").starter

2 Likes

How would I use this?

That function provides the module as it’s return value, so if you don’t assign the value, it’s lost after that function.

Other than that, here’s some examples compared to normal imports:

import module
# or
module = __import__("module")
# --------------------------------------
from module import variable
# or
variable = __import__("module").variable
# --------------------------------------
from module import a,b
# or
a = __import__("module").a
b = __import__("module").b

Got it. I’ll try it now.

Great! It works! TYSM!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.