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
Post a Comment