Python online run code assistant _python

Source: Internet
Author: User
Tags button type python script

The Python code-run assistant lets you enter the Python code online, and then executes the code with a Python script running on the computer. The principle is as follows:

Enter the code in the Web page:

Click the Run button and the code is sent to the running Python code run assistant;

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

Web page shows code execution results:

Download

Right-click to save target as: learning.py

Alternate Download Address: learning.py

Complete code:

#!/usr/bin/env Python3 #-*-coding:utf-8-*-R ' ' learning.py A Python 3 tutorial from http://www.liaoxuefeng.com Us Age:python3 learning.py ' ' Import sys def check_version (): v = sys.version_info If v.major = 3 and V.minor >= 4 : Return True print (' Your The current Python is%d.%d. Please use the Python 3.4. '% (V.major, V.minor)) return to False if not check_version (): Exit (1) Import OS, Io, JSON, Subpro
Cess, tempfile from urllib Import parse from wsgiref.simple_server import make_server EXEC = sys.executable PORT = 39093 HOST = ' local.liaoxuefeng.com:%d '% PORT TEMP = tempfile.mkdtemp (suffix= ' _py ', prefix= ' learn_python_ ') INDEX = 0 def main (): httpd = Make_server (' 127.0.0.1 ', PORT, application) print (' Ready for Python code on port%d ... '% port) httpd.serve  _forever () def get_name (): Global Index index = index + 1 return ' test_%d '% index def 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 Fpath def decode (s): Try:return s.decode (' Utf-8 ') except unicoded  Ecodeerror:return s.decode (' GBK ') def application (environ, start_response): host = Environ.get (' http_host ') method =  Environ.get (' request_method ') path = Environ.get (' path_info ') if method = = ' get ' and path = = '/': Start_response (' 200 OK ', [(' Content-type ', ' text/html ')] return [b '  

Run

To run a command under a directory that holds learning.py:

Copy Code code as follows:

C:\users\michael\downloads> python learning.py

If you see ready for Python code on port 39093 ... indicates that the operation was successful, do not close the command line window, and minimize the run to the background:

Try the effect

Browsers that need to support HTML5:

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.