0

how to excute python code from input and display the output?

I made a telegram bot using python.. I have two files one is bot.py and other is sever.py and it works flawlessly with normal messages... but what I want... if a user send the python code to the bot then bot should excute the code and then output the result to the user.... here is my attempt in server.py but I am getting nameError : name python is not defined input in telegram Bot : print("hello world") output in telegram Bot : hello world My attempt : https://code.sololearn.com/cjPmrilNk714/?ref=app

4th Feb 2021, 5:13 PM
Ratnapal Shende
Ratnapal Shende - avatar
5 Respostas
+ 2
This is working though. Is the problem occurring when in telegram? https://code.sololearn.com/cA15A15a1A5A
5th Feb 2021, 10:19 AM
noteve
noteve - avatar
+ 1
Cyan Jan Markus Sorry for disturbing you guys...please help me ..
5th Feb 2021, 9:33 AM
Ratnapal Shende
Ratnapal Shende - avatar
+ 1
Cyan yes bro when I give print(" hello world") command to the telegram bot then in my server. py error is coming NameError: name 'python' is not defined what to do bro please help! 🙁
5th Feb 2021, 12:20 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 1
Cyan bro now it is working I don't know how but no error I am facing now.. but now the problem is it's printing "hello world" in server. py python console it is not sending the output to the bot.. 🙁
6th Feb 2021, 10:24 AM
Ratnapal Shende
Ratnapal Shende - avatar
+ 1
Ratnapal Shende Yeah, I think that is because exec just execute the program and won't return the output. See this, and try to copy that output of exec then that will be the text which will be send by your bot. https://stackoverflow.com/questions/3906232/JUMP_LINK__&&__python__&&__JUMP_LINK-get-the-print-output-in-an-exec-statement
6th Feb 2021, 10:58 AM
noteve
noteve - avatar