Python online running code assistant and python code Assistant

Source: Internet
Author: User

Python online running code assistant and python code Assistant

The Python code execution assistant allows you to input Python code online and then run the code using a Python script running on the local machine. The principle is as follows:

Enter code on the webpage:

Click the Run button to send the code to the Python code running assistant running on the local machine;

The Python code execution assistant saves the code as a temporary file and then calls the Python interpreter to execute the code;

The code execution result is displayed on the webpage:

Download

Right-click and choose "Save As: learning. py ".

Standby: learning. py

Complete code:

#! /Usr/bin/env python3 #-*-coding: UTF-8-*-r ''' learning. pyA Python 3 tutorial from http://www.liaoxuefeng.comUsage: python3 learning. py '''import sysdef check_version (): v = sys. version_info if v. major = 3 and v. minor> = 4: return True print ('your current python is % d. % d. please use Python 3. 4. '% (v. major, v. minor) return Falseif not check_version (): exit (1) import OS, io, json, subprocess, tempfil Efrom urllib import parsefrom wsgiref. simple_server import make_serverEXEC = sys.exe cutablePORT = 39093 HOST = 'local .liaoxuefeng.com: % d' % PORTTEMP = tempfile. mkdtemp (suffix = '_ py', prefix = 'learn _ python _') INDEX = 0def main (): httpd = make_server ('2017. 0.0.1 ', PORT, application) print ('Ready for Python code on port % d... '% PORT) httpd. serve_forever () def get_name (): global INDEX = INDEX + 1 ret Urn 'test _ % d' % INDEXdef write_py (name, code): fpath = OS. path. join (TEMP, '% s. py '% name) with open (fpath, 'w', encoding = 'utf-8') as f: f. write (code) print ('Code wrote to: % s' % fpath) return fpathdef decode (s): try: return s. decode ('utf-8') encoding t UnicodeDecodeError: return s. decode ('gbk') def application (environ, start_response): host = environ. get ('HTTP _ host') method = environ. get ('request _ METHO D') path = environ. get ('path _ info') if method = 'get' and PATH = '/': start_response ('2017 OK ', [('content-type ', 'text/html')]) return [B '

Run

Run the following command in the directory where learning. py is stored:
Copy codeThe Code is as follows:
C: \ Users \ michael \ Downloads> python learning. py

If you see Ready for Python code on port 39093..., it indicates that the operation is successful. Do not close the command line window and try to run it in the background:

Try the results

HTML5 browsers:

IE> = 9
Firefox
Chrome
Sarafi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.