0
我在寫一個Python腳本,它將ssh放入一個框中(使用parakimo)並運行命令。我想爲stdout/stderr創建一個對象並打印輸出。閱讀列表元素的Python類,__ str__和類問題
我是否正確地將名單傳遞給類?我是否正確地在課堂上遞交了 列表?
我想利用
__str__
方法,所以我可以打印(對象)。 我該如何正確地做到這一點?- 我打算使用這個類的2個實例,因爲我會做2 單獨的sss.exec_command(命令)。我是否在課堂上把這個功能包裝起來,浪費記憶力 ?我想利用OO來高效組織並嘗試利用python的面向對象功能。
class read_log:
def __init__(self, exit_status, *tuple_list):
self.exit_status = exit_status
self.tuple_list = tuple_list
if exit_status:
output = stderr.readlines()
else:
output = stdout.readlines()
del output[0]
del output[-1]
def __str__(self)
return ''.join(output)
def create():
stdin, stdout, stderr=ssh.exec_command("/home/one/script.sh")
exit_status = stdout.channel.recv_exit_status()
x = readlog(exit_status, stdin, stdout, stderr)
print(x)
tuple_list不會奇蹟般地翻譯e進入std *對象或者... – marcoseu
@marcoseu:好點,解決。 –
我不斷收到<__ main __。0x7f39fd648878> ReadLog實例>。爲什麼是這樣?順便說一下,我將類名改爲ReadLog而不是read_log。另外,std *對象究竟是什麼? – dman