Err, how about the venerable:
if len(str) > 0:
if str[-1:] == ",":
str = str[:-1]
, rstrip , - , awk, , . .
, . :
str = "hello,"
print str.rstrip(",")
str = "hello,\n"
print str.rstrip(",")
print str.rstrip(",\n")
:
hello
hello,
hello
, , rstrip ",\n".
, , :
uptime = subprocess.Popen([r"uptime"], stdout=subprocess.PIPE)
uptime_stdout = uptime.communicate()[0]
print uptime_stdout
awk = subprocess.Popen([r"awk", "{print $11}"], stdin=subprocess.PIPE)
awk_stdin = awk.communicate(uptime_stdout)[0]
print repr(awk_stdin)
temp = awk_stdin
tem = temp.rstrip("\n")
logfile = open('/usr/src/python/uptime.log', 'a')
logfile.write(tem + "\n")
logfile.close()
print , ?
uptime $11:
23:43:10 up 5:10, 0 users, load average: 0.00, 0.00, 0.00
.
, script.