As the title says I need the user to input the name of an account eg: Main or Spam and then import that specific module.
I tried using this but python expects to find a module called "Accounts" i wanted it to look for the module with the same name as the input
Account=input("Which account to use?: ")
if Account in acc.accounts:
import Account as info
>Solution :
You would want to use import_module: https://docs.python.org/3/library/importlib.html#importlib.import_module
module.py:
def foo():
print("bar")
In the script:
from importlib import import_module
m = import_module("module") ## refers to module.py
m.foo() ## prints "bar"
In your code, you would want to change
import Account as info
to
info = import_module(Account)
You would want to make sure the module you are trying to import is also on your $PATH.