How not to name variables
This is is a Python line of code which I found in my project I work with two colleagues:
for mid, mda, xmht, xmat, mhs, mas, mehs, meas, mphs, mpas, mrou in q: # ....
No comments.
This is is a Python line of code which I found in my project I work with two colleagues:
for mid, mda, xmht, xmat, mhs, mas, mehs, meas, mphs, mpas, mrou in q: # ....
No comments.
Nie mieliśmy kości na sesję, to trzeba było coś napisać. NWOD-owy rzucacz kośćmi w Pythonie:
#!/usr/bin/python import time import random import sys # argumenty: ile_scian = int(sys.argv[1]) # ilusciennymi koscmi rzucamy sukces = int(sys.argv[2]) # od ilu oczek jest sukces ile_rzutow = int(sys.argv[3]) # ile razy rzucamy def kostka(sciany): rzut = random.randint(1, sciany) print rzut return rzut print '------------------------------' random.seed() sukcesy = 0 for i in range(0, ile_rzutow): rzut = kostka(ile_scian) if rzut >= sukces: sukcesy += 1 while rzut == ile_scian: print 'Przerzut!' rzut = kostka(ile_scian) if rzut >= sukces: sukcesy += 1 print print "Sukcesy: ", sukcesy
It’s for my Python Course. It provides only very basic HTTP, but yet can be used for simple WWW hosting. Source.
Features:
TODOs:
To run just edit pyhttpd.conf and change Port and Document root. Then type “python pyhttpd.py” and it should be now listening for connections.
How to run a python script and its output send to client? Pyhttpd checks if the requesting file is a python one. If so then it opens a python interpreter by a pipe, sends _GET and _POST dictionaries and file contents. And finally, sends interpreter outputs to client.
_GET and_POST are just dictionaries with variable names as keys. So if there is a foobar.py?i=500 request then _GET will be { ‘i’ : ‘500′ } (note that this is always a string value).
It’s GPL if someone asked.
Recent Comments