Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102468

import cannot be used inside eval

From 阎兆珣 <yanzhaoxun@greendh.com>
Newsgroups comp.lang.python
Subject import cannot be used inside eval
Date 2016-02-04 13:03 +0800
Message-ID <mailman.46.1454575313.30993.python-list@python.org> (permalink)

Show all headers | View raw


   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 run a .py file that user specifies.

   eval() does fine with print() command

   but fails to call import command

   Is it a but or a taboo?

   Thanks

   Zhaoxun Yan          

   Option Product Manager

   Gelin Dahua Futures Co.Ltd

    T: +86 10 56711783

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

import cannot be used inside eval 阎兆珣 <yanzhaoxun@greendh.com> - 2016-02-04 13:03 +0800

csiph-web