Python 2 print headers and content of url

Leave a comment


python -c 'import urllib2; resp = urllib2.urlopen("http://localhost:10888/cgi-bin/hello.py"); print resp.info(), resp.read()'

Python 3 print headers and content of url

Leave a comment


python3 -c 'import urllib.request; resp = urllib.request.urlopen("http://localhost:10888/cgi-bin/hello.py"); print(resp.info(), resp.read().decode("utf-8"))'

Python 3 CGI web server with cgi-bin directory

3 Comments


python3 -c 'import http.server; http.server.HTTPServer(("", 10888), http.server.CGIHTTPRequestHandler).serve_forever()'

Python cgi web server with cgi-bin and htbin

Leave a comment


python -m CGIHTTPServer 10080

Python 3 web server the current directory

Leave a comment


python3 -m http.server 10030

Python web server the current directory

Leave a comment


python -m SimpleHTTPServer 10080

Python as a shell

Leave a comment


ipython -p pysh

Reversing a string in python – version special case

Leave a comment


python -c 'print "The rain in spain."[::-1]'

Reversing a string in python – version after sleeping on it

Leave a comment


python -c 'print "The rain in spain."[-1::-1]'

Reversing a string in python – version the first

6 Comments


python -c 's = "The rain in spain falls mainly on the plain."; print "".join(s[c] for c in xrange(len(s) - 1, -1, -1))'

python list sort

1 Comment

python -c 'x=["hello","my","friend"];x.sort();print x'

python one liners start with -c

Leave a comment

python -c 'hw=[x for x in "hello world".title().partition()];x=len(hw);(x*"%s"+"!")%tuple(hw)'

Follow

Get every new post delivered to your Inbox.