Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
91 views
in Technique[技术] by (71.8m points)

Single Line Python Webserver

I seem to remember seeing a single line implementation of a webserver a couple of years ago. I'm aware of SimpleHTTPServer and it's like, and that's not it - I think this was using Socket and select().

I thought it was on the Python Tutor mailing list, but an archive search hasn't revealed anything, nor has a google search. I was wondering if anyone here might have further leads I could look up - or ideally a link to the original.

Although I guess it's entirely possible that the original author has taken it down out of shame...

question from:https://stackoverflow.com/questions/8058793/single-line-python-webserver

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm pretty sure you can't have a webserver using sockets and select() on one line of code. Not even using semicolons, you'd have to have some loops and control structures.

Are you sure this isn't what you are looking for?

$ python -m SimpleHTTPServer 8000
Serving HTTP on 0.0.0.0 port 8000 ...

Python 3 version: python -m http.server 8000


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...