Python Http Server Code Explanation? -


i have seen many examples of http servers written in python on internet , include

if sys.argv[1:]:     port = int(sys.argv[1]) else:     port = 8000 

can explain line me? thanks

sys.argv list of strings containing arguments passed python script commandline. sys.argv[0] name of script , passed in implicitly. arguments passed in user stored in sys.argv[1], sys.argv[2], etc.

with in mind, code can explained follows:

# if there more 1 item in sys.argv... if sys.argv[1:]:     # ...get sys.argv[1], convert integer, , assign port     port = int(sys.argv[1]) # otherwise, assign port 8000 else:     port = 8000 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -