Re: [Tutor] Single line webserver
>Windows Command Prompt gotta be the most powerful language on earth, it >has a full-blown server in a single word: >C:\Program Files\Apache Software Foundation\Apache2.2\bin> httpd.exe Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Single line webserver [was: Tutor Digest, Vol 93, Issue 38]
Rich Lovely wrote: I'd like to draw your attention to my original message: "a google search is similarly lacking in relevant results." Shouldn't it be clear from how easy it is to find SimpleHttp that it clearly /isn't/ what I'm looking for? Perhaps I should have mentioned that, but I thought I'd made it clear I'd tried a websearch. Yes, you should have mentioned that SimpleHttp was not the one-liner you were looking for. That would have been useful to know :) Your request was for a one-liner web server, and you claimed to have done a search which came up with nothing relevant. Since a simple search did in fact come up with an apparently relevant one-liner, the most obvious conclusions were that your search skills are very lousy, or that you were mistaken (i.e. lying) about having attempted to search first. Coming from an apparent first-time poster with no reputation I was aware of, neither would have surprised me. I'm glad that neither is actually the case. The code I remember was a Socket-based webserver, written in one - albeit rather long - line. That would have been useful information to have mentioned at the time. For what little it's worth, here's a 15 line socket-based web server: import socket template = ('HTTP/1.0 200 OK\n\nWelcome %s!' 'Header..and body.Your request was: ' '"%s"') sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind(('', 8080)) sock.listen(1) print "Listening on port 8080" while True: client, address = sock.accept() cfile = client.makefile('rw', 0) cfile.write(template % (str(address), cfile.readline().strip())) cfile.close() client.close() Save this as "web.py", run "python web.py", and then in your browser go to http://localhost:8080 Turning this into a one-liner is left as an exercise. This may be useful: http://pauldotcom.com/2011/10/python-one-line-shell-code.html P.S. I note you're replying to the digest. Thank you for trimming your reply, rather than including the entire digest, but please note the request at the top of each digest: When replying, please edit your Subject line so it is more specific than "Re: Contents of Tutor digest..." -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Single line webserver
On 11/08/2011 10:23 AM, Rich Lovely wrote: Hi all, I was part of this list a couple of years ago, and a recent discussion at a python dojo brought to mind something I'd seen then: a one-liner (potentially single statement) webserver. I'm pretty sure it was posted to this list, but I can't find it in the archives, and a google search is similarly lacking in relevant results. I was wondering if anyone (maybe the original author?) had a copy they could send me. Windows Command Prompt gotta be the most powerful language on earth, it has a full-blown server in a single word: C:\Program Files\Apache Software Foundation\Apache2.2\bin> httpd.exe ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Single line webserver
On 07/11/11 23:23, Rich Lovely wrote: a one-liner (potentially single statement) webserver. There is a python module in the standard library that implements a basic webserver, presumably it was based on that. Try the docs for the library modules... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Single line webserver
Rich Lovely wrote: Hi all, I was part of this list a couple of years ago, and a recent discussion at a python dojo brought to mind something I'd seen then: a one-liner (potentially single statement) webserver. I'm pretty sure it was posted to this list, but I can't find it in the archives, and a google search is similarly lacking in relevant results. I was wondering if anyone (maybe the original author?) had a copy they could send me. https://duckduckgo.com/html/?q=python%20one%2Dliner%20web%20server Hits #2 #3 and #4 are: http://tobyho.com/2010/04/26/one-liner-webserver-with/ http://www.garyrobinson.net/2004/03/one_line_python.html http://aroberge.blogspot.com/2010/08/my-favourite-python-one-liner.html -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Single line webserver
Hi all, I was part of this list a couple of years ago, and a recent discussion at a python dojo brought to mind something I'd seen then: a one-liner (potentially single statement) webserver. I'm pretty sure it was posted to this list, but I can't find it in the archives, and a google search is similarly lacking in relevant results. I was wondering if anyone (maybe the original author?) had a copy they could send me. Rich "RoadieRich" Lovely There are 10 types of people in the world: Those who know binary, Those who do not, And those who are off by one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor