简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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