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


Groups > comp.lang.python > #102468 > unrolled thread

import cannot be used inside eval

Started by阎兆珣 <yanzhaoxun@greendh.com>
First post2016-02-04 13:03 +0800
Last post2016-02-04 13:03 +0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#102468 — import cannot be used inside eval

From阎兆珣 <yanzhaoxun@greendh.com>
Date2016-02-04 13:03 +0800
Subjectimport cannot be used inside eval
Message-ID<mailman.46.1454575313.30993.python-list@python.org>
   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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web