Python how to execute code from a txt file
问题 I want to keep a piece of code in a txt file and execute it from my Python script. For example in the txt file there is print("ok") I want my programme to print ok and not print print("ok ") . How can I do this? 回答1: Doing what you want usually is a security risk, but not necessarily so. You'll definitely have to notify the user about potential risk. There is more than one program using execfile() or compile() and exec statement to provide plug-ins system. There is nothing so ugly about it,