简体   繁体   English

如何从 Pastebin 代码段运行 Python 代码?

[英]How to run a Python code from a Pastebin snippet?

Is there any way to implement a code saved on pastebin in your Python application?有什么方法可以在您的 Python 应用程序中实现保存在 pastebin 中的代码?

Example:例子:

a = 1
# [load pastebin content: a=a+1]
print(a)

Is that possible with any command?任何命令都有可能吗?

Yes, you can!是的你可以!

import requests

def pasterun(post):
    url = f"https://pastebin.com/raw/{post}"
    code = requests.get(url).text
    exec(code)

url = 'https://pastebin.com/JRfkiLM8'
*_, post = url.split('/')
pasterun(post)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM