How to call 'from x import *' where x is a variable in Python

Viewed 167

I am running several python scripts that are exactly the same except for a prefix on the variables. (Just for clarity, I am working with Tweepy and the Twitter API).

I have named each API credential xx_apicred.py, yy_apicred.py, etc, and these are saved as a separate file in the folder.

Also, I have tables named xx_info, yy_info, etc. This part is easy to change through string manipulation.

I would like to change this so that it is one file where I pass the xx string as an argument. This works for everything except the from xx_cred import*

When I replace it with a string variable, I get the error that ImportError: No module named 'var'

Is there a way I can import through a variable?

3 Answers
Related