samedi 21 avril 2018

Execute code from non .py file in python

I am trying to make python execute a random line of code from a given file. Let's say I have a file called "code_lines". This file contains random pieces of python code, ex.

print("This is a random message")
print("This is another message")
print("This is getting boring")

Is it possible for python to select a random line from that file and run it as code?




Aucun commentaire:

Enregistrer un commentaire