+ 1

executing string

How can I execute a string? When it is in variable! -- Like opening a file having a Source code --

4th Dec 2018, 2:51 PM
Bhavik Mahalle
Bhavik Mahalle - avatar
5 Réponses
+ 1
Pls tell me how
4th Dec 2018, 3:01 PM
Bhavik Mahalle
Bhavik Mahalle - avatar
+ 1
Pls tell me
4th Dec 2018, 3:02 PM
Bhavik Mahalle
Bhavik Mahalle - avatar
+ 1
Let's say you have a file containing this source-code called myCode.py age = 27 msg = "I am "+ (str(age)) + " years old" print(msg); if you want to execute that code, you'll have to open the file, read it's contents and execute them. exec(open("myCode.py").read)
4th Dec 2018, 4:25 PM
Dlite
Dlite - avatar
0
What do you mean by executing s string
4th Dec 2018, 4:18 PM
Dlite
Dlite - avatar
0
Thanks
17th Aug 2020, 10:03 AM
Bhavik Mahalle
Bhavik Mahalle - avatar