-1
a = input('Enter something:') #e.g. input is print('Hello World')
# some function
print(a) #and then we get only `Hello World` out as we use print

I already researched executing shell commands via python but nothing related what I want to do. Do I need to change to language that's not python? Is it even possible to do?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
P-CAST
  • 53
  • 7

2 Answers2

2

For statements, use exec(string) (Python 2/3) or exec string (Python 2):

So rather than printing a it, use exec

Just as an aside, I would say this is highly insecure if you plan to use it in any software as is.

aqibjr1
  • 651
  • 5
  • 21
0

You can use exec:

>>> a = input("Enter something: ")
Enter something: print("hello world")
>>> exec(a)
hello world
Matias Lopez
  • 94
  • 1
  • 7