我有一個使用popen()函數作爲數組返回stdout的函數。以'u'爲前綴的python數組元素
使用Python3陣列被正確返回,但下蟒2.7各元素的前綴與 'U'
def exe(cmd):
from subprocess import Popen, PIPE, STDOUT
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
arr = p.stdout.read().decode().split("\n")
print(arr)
del arr[-1]
if(arr[0]=='not found.'): arr = [];
return arr
[u'10-000801d5a12d」,U '']
在哪裏這個'你'來自我如何防止它?
你不會阻止它。當你打印清單時,你會得到內容的表示,而不是價值。 – Matthias
只有部分口頭回答 - 通過切換Python 3.x來防止它!據我所知,關於3.x前Python的最糟糕的事情是字符串的unicode支持。 – rlms