Apr-19-2017, 06:51 AM
(This post was last modified: Apr-19-2017, 12:56 PM by sparkz_alot.)
Hello all,
My first post here. Newbie to python and I want to improve the below code mainly for learning purpose. Let me first post it and then explain what how I want to improve it.
- I want to get the user to specify the raw_input as a command line argument (i.e ./script.py FE-<name>:<ip>:<port> | BE-<name><ip>:<port>).
- I want to add another part to the template called "backend bk:<somename>:<someip>:<someport>". Script should pick up the correct user input to the right section (ie: "FE-<name>:<ip>:<port>" to the "frontend fe" section and "BE-<name><ip>:<port>" to the backend section.
- once user is done inputting the parameters I want to restart a service i.e:service abc restart. Please note that I want to wait before user adds all the entries before restarting the service.
Please help out gentleman. I really want to come up to speed.
My first post here. Newbie to python and I want to improve the below code mainly for learning purpose. Let me first post it and then explain what how I want to improve it.
VAR1, VAR2, VAR3= raw_input("Enter ip, port and name seperated by colan").split(":") template ="""frontend fe:{0}:bind:{1} mode tcp bind {0}:{1} name {2}""" BLOCK = template.format(VAR1,VAR2,VAR3) with open("file.txt", "a") as myfile: myfile.write(BLOCK)As you can see I'm appending to the "file.txt" based on user inputs. Once the user specify the ip address and the port (i.e: 10.1.2.2:443:somename) it would construct the text in var "template" sending the correct value to the corresponding "{}". I want to understand the best way to do the following.
- I want to get the user to specify the raw_input as a command line argument (i.e ./script.py FE-<name>:<ip>:<port> | BE-<name><ip>:<port>).
- I want to add another part to the template called "backend bk:<somename>:<someip>:<someport>". Script should pick up the correct user input to the right section (ie: "FE-<name>:<ip>:<port>" to the "frontend fe" section and "BE-<name><ip>:<port>" to the backend section.
- once user is done inputting the parameters I want to restart a service i.e:service abc restart. Please note that I want to wait before user adds all the entries before restarting the service.
Please help out gentleman. I really want to come up to speed.