Best Python code snippet using fMBT_python
main.py
Source:main.py
...5print()6token = open('token.txt','r')7bot = Bot(token.read())8token.close()9def execPython(code):10 log = '>>starting python\n'11 try:12 log += subprocess.check_output('docker run --rm -t python timeout -s SIGKILL 10 python -c'.split()+[code], timeout = 15, encoding = 'utf-8')13 log += '>>python finished'14 errmsg = none15 except subprocess.CalledProcessError as e:16 errname = (124==e.returncode) and "timeout" or (1==e.returncode) and "error" or "%s"%e17 errmsg = '`Python interrupted (%s)`'%errname18 log += e.output19 log += '>>python crashed\n'20 except:21 errmsg = 'Unknown Error'22 log += '>>python crashed\n'23 return log, errmsg24def onMsg(update):25 if 'message' in update: msg = update['message']26 elif 'edited_message' in update: msg = update['edited_message']27 else: return28 if 'text' in msg: text = msg['text']29 else: return30 chat = msg['chat']['id']31 code = text32 if 'entities' in msg:33 ents = msg['entities']34 for e in ents:35 if 'pre'==e['type']:36 o = e['offset']37 l = e['length']38 code = text[o:(o+l)]39 break40 output, *errmsg = execPython(code)41 bot.sendMessage(chat,output)42 if errmsg: bot.sendMessage(chat, *errmsg, markdown = True)43bot.onMessage = onMsg...
sqlite3_exec.py
Source:sqlite3_exec.py
1def generate_html(s):2 title='SQLite3 Execution !!!'3 script=r'''4 function execPython()5 {6 var inputer=document.getElementById('pycode');7 var pyresult=document.getElementById('pyresult');8 if(inputer.value){9 var prevalue=inputer.value10 var xhr=new XMLHttpRequest();11 xhr.onreadystatechange=function(){12 if(xhr.readyState==4 && xhr.status==200)13 {14 pyresult.value+=prevalue+':\n';15 pyresult.value+='\t'+xhr.responseText+'\n';16 }17 };18 xhr.open('POST','/script/sqlite3_exec_postdata.html',true);19 xhr.send(inputer.value);20 inputer.value='';21 }22 }23 24 '''25 style=r'''26 #pycode , #pyresult{27 width: 90%;28 }29 #pycode{30 height: 5em;31 }32 #pyresult{33 height: 15em;34 35 }36 '''37 body=r'''38 <textarea id='pycode' ></textarea>39 <br />40 <button id='submit' onclick='execPython();'>æ交</button>41 <button onclick='document.getElementById("pyresult").value="";'>æ¸
é¤</button>42 <hr />43 <textarea id='pyresult' readonly style="overflow-y: scroll;" ></textarea>44 '''45 html=s.hf.format_html(title=title,script=script,body=body,style=style);...
python_exec.py
Source:python_exec.py
1def generate_html(s):2 title='Python Execution !!!'3 script=r'''4 function execPython()5 {6 var inputer=document.getElementById('pycode');7 var pyresult=document.getElementById('pyresult');8 9 var xhr=new XMLHttpRequest();10 xhr.onreadystatechange=function(){11 if(xhr.readyState==4 && xhr.status==200)12 {13 pyresult.value=xhr.responseText;14 }15 };16 xhr.open('POST','/script/python_exec_postdata.html',true);17 xhr.send(inputer.value);18 }19 '''20 style=r'''21 #pycode , #pyresult{22 width: 90%;23 }24 #pycode{25 height: 20em;26 }27 #pyresult{28 height: 10em;29 30 }31 '''32 body=r'''33 <textarea id='pycode' ></textarea>34 <br />35 <button id='submit' onclick='execPython();'>æ交</button>36 <hr />37 <textarea id='pyresult' readonly ></textarea>38 '''39 html=s.hf.format_html(title=title,script=script,body=body,style=style);...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!