1
pydoc을 사용하면 브라우저의 내 PYTHONPATH에 추가 된 디렉토리의 Python 모듈 및 패키지에 대한 문서를 볼 수 있습니다. 해당 파일의 전체 코드를 탐색 할 수있는 방법이 있습니까? localhost:8080
에가는브라우저에서 Python 파일의 내용/코드를 탐색하는 프로그램과 유사한 pydoc?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import with_statement
import CGIHTTPServer, SimpleHTTPServer, BaseHTTPServer
import os
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter
from io import open
class SourceViewer(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
path = os.path.join(os.getcwdu(), self.path[1:])
if os.path.exists(path) and path.endswith(u'.py'):
with open(path) as file:
code = file.read()
hl = highlight(code, PythonLexer(), HtmlFormatter(noclasses=True, linenos=u'table'))
self.send_response(200)
self.end_headers()
self.wfile.write(str(hl).encode('UTF-8'))
return
else:
super(self.__class__, self).do_GET()
if __name__ == u"__main__":
server = BaseHTTPServer.HTTPServer((u'localhost', 8080), SourceViewer)
server.serve_forever()
no data received
메시지를 보여줍니다
헤이 에두아르도
이
파이썬 3에 대한 예입니다 ! '3to2'를 사용하여 코드를 변환했습니다. (편집 된 원본 게시물을 참조하십시오.) 그러나 'no data received'메시지가 나타나면 어떻게 데이터를 전달해야합니까? – Bentley4너무 나빠요. 몇 분 후에 집에 가면 시험해 보겠습니다. –
SimpleHTTPRequestHandler에 대한'super()'호출이 실패한 것처럼 보입니다. 이전 스타일의 클래스 일 수도 있습니다. 이상하게 보이지만 실제로 확인하지는 않았을 수도 있습니다. 편집에서 새 버전을 확인하십시오. 부모 클래스에 대한 명시 적 호출과 함께 작동합니다. –