我该如何从字符串末尾删除逗号?我尝试了
这是输出结果:
awk = subprocess.Popen([r"awk", "{print $10}"], stdin=subprocess.PIPE)
awk_stdin = awk.communicate(uptime_stdout)[0]
print awk_stdin
temp = awk_stdin
t = temp.strip(",")
我尝试了t = temp.strip(“,”)
,两种方法都不起作用。
这是代码:
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()
这是输出结果:
17:07:32 up 27 days, 37 min, 2 users, load average: 5.23, 5.09, 4.79
5.23,
None
Traceback (most recent call last):
File "uptime.py", line 21, in ?
tem = temp.rstrip("\n")
AttributeError: 'NoneType' object has no attribute 'rstrip'
temp
是什么吗? - SilentGhost