By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,396 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

Execute Code in String variable

P: 1
I want to execute code which is in a string variable
like
if i have a string like
str='import xyz'
then I want to execute import xyz in my program.
Is there any way to do this ? :confused:
Jul 19 '06 #1
Share this Question
Share on Google+
1 Reply


P: 12
dvs
Expand|Select|Wrap|Line Numbers
  1. exec('import xyz')                           # in general
  2. mod = __import__('xyz', globals(), locals()) #in case dynamically loading a module
Jul 20 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.