브 라 우 저 에서 Python 코드 를 직접 실행 합 니 다.
13655 단어 Python/Rubypython
https://raw.githubusercontent.com/michaelliao/learn-python3/master/teach/learning.py
cmd 조작E:\python\code>python learning.py
Ready for Python code on port 39093...
127.0.0.1 - - [29/Nov/2016 14:51:17] "GET / HTTP/1.1" 200 216
127.0.0.1 - - [29/Nov/2016 14:51:17] "GET /favicon.ico HTTP/1.1" 400 23
이렇게 해서 39093 포트 를 열 고 브 라 우 저 에 직접 접근 할 수 있 습 니 다.
http://127.0.0.1:39093/
하지만 이렇게 코드 를 제출 할 때 bad request 를 알려 줍 니 다.
그래서 hosts 파일 을 설정 해 야 합 니 다.
127.0.0.1 local.liaoxuefeng.com
다음 방식 으로 접근:
http://local.liaoxuefeng.com:39093/
백업 하 다
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r'''
learning.py
A Python 3 tutorial from http://www.liaoxuefeng.com
Usage:
python3 learning.py
'''
import sys
def 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 False
if not check_version():
exit(1)
import os, io, json, subprocess, 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 UnicodeDecodeError:
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'Learning Python
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
파이썬을 사용하여 10진수를 bin, 8진수 및 16진수 형식으로 변환하는 방법은 무엇입니까?텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.