Re: import cannot be used inside eval

2016-02-04 Thread Gary Herron
On 02/03/2016 09:03 PM, 阎兆珣 wrote: a = input("tell me which py to execute: ") print(a) print('import '+a) print(type('import'+a)) eval('print(a)') Eval is meant to evaluate Python expressions. The import is a statement, not an expression. Also, it's a bad idea to use e

Re: import cannot be used inside eval

2016-02-04 Thread Chris Angelico
On Thu, Feb 4, 2016 at 4:03 PM, 阎兆珣 wrote: >a = input("tell me which py to execute: ") > >print(a) > >print('import '+a) > >print(type('import'+a)) > >eval('print(a)') > >try: > >eval('import '+a) > >except Exception as e: > >print('Error: ', e) > >

import cannot be used inside eval

2016-02-04 Thread 阎兆珣
a = input("tell me which py to execute:  ") print(a) print('import '+a) print(type('import'+a)) eval('print(a)') try:     eval('import '+a) except Exception as e:     print('Error: ', e) ##while True: ##    pass @python 3.4.2 this code attempts to