Before you upload any criticism, first let me congratulate you on how your first Python program works. Moving from one language to another can be a daunting task, constantly struggling with syntax issues and hunting through unfamiliar libraries.
The most cited PEP-8 style directive, but this is only a guide, and at least part of it is ignored ... no, I mean, this does not apply to any particular situation, with all due respect to the authors and participants of the recommendations: -).
I cannot compare it with PHP, but compared to other Python applications it is pretty clear that you follow style conventions from other languages. I did not always agree with many things that other developers said that you should do, but over time I realized why using conventions helps to communicate what the application is doing and will help other developers help you.
Raise exceptions, not rows.
raise 'Server or group' + sectionname + 'not found in' + configfile
becomes
raise RuntimeError ('Server or group' + sectionname + 'not found in' + configfile)
There is no space before the ":" at the end of the "if" or "for" and do not put multiple statements on the same line and do not agree to put spaces around the statements. Use variable names for objects and stick to
i and
j for loop index variables (for example, our FORTRAN workshop ancestors):
for i in grouplist: servers + = getServers (i)
becomes:
for section in grouplist:
servers + = getServers (section)
Containers can be tested for content without getting their length:
while len (threadlist)> 0:
becomes
while threadlist:
and
if command.strip () == "":
becomes
if command.strip ():
Separation of a tuple usually does not fit in brackets on the left side of the statement, and the command logic is a bit confusing. If there are no arguments, then .join (...) will be an empty string:
(options, args) = parser.parse_args ()
if options.verbose: print "floep 0.1"
command = "" .join (args)
if command.strip () == "": parser.error ('no command given')
becomes
options, args = parser.parse_args ()
if options.verbose:
print "floep 0.1"
if not args:
parser.error ('no command given')
command = "" .join (args)
Python for the loop has an unusual else clause, which is executed if the loop goes through all the elements without a break:
for server in threadlist:
foundOne = False
if not server.isAlive ():
... snip ...
foundOne = True
if not foundOne:
time.sleep (0.010)
becomes
for server in threadlist:
if not server.isAlive ():
... snip ...
break
else:
time.sleep (0.010)
Getting a list of strings and then combining them back is a little longer:
result = proc.readlines ()
strresult = ''
for line in result: strresult + = line
self.result = strresult
becomes
self.result = proc.read ()
Using the library is useful, check the subprocess module, it is slightly updated.
Your data types are fine.
And you will get many other anwsers :-)