我需要使用python以html表格格式获取输出

我需要使用python以html表格格式获取输出,python,html,Python,Html,请在下面找到我的代码和输出,以转换为html表格格式 cmd = "ls -Altr hpsm_%s.* | tail -n -1 | awk '{print $6,$7,$8,$9'}" % i output1 = [commands.getoutput(cmd).split("\n")] print(output1) 输出: 输出类型列表需要以html表格格式获取 [['Dec 1 03:18 hpsm_tAlert_ALL_oracle_TBS_offline.log']] [['ls:

请在下面找到我的代码和输出,以转换为html表格格式

cmd = "ls -Altr hpsm_%s.* | tail -n -1 | awk '{print $6,$7,$8,$9'}" % i
output1 = [commands.getoutput(cmd).split("\n")]
print(output1)
输出: 输出类型列表需要以html表格格式获取

[['Dec 1 03:18 hpsm_tAlert_ALL_oracle_TBS_offline.log']]
[['ls: cannot access hpsm_tAlert_K8s_kubernetes_health_by_POD.*: No such file or directory']]
[['Dec 29 03:42 hpsm_tAlert_NN_WMS_endpoint-message-count_MSE.log']]
[['Nov 24 03:48 hpsm_tAlert_NN_ecom_version_check.log']]
[['Nov 24 03:48 hpsm_tAlert_NN_ecom_version_check_all_farms.log']]
[['Jan 3 03:55 hpsm_tAlert_NN_metrics_fileSystem.log']]
预期产量

Alert Name                           | status time

tAlert_ALL_oracle_TBS_offline.log    | Dec 1 03:18

tAlert_K8s_kubernetes_health_by_POD  | NA
下面是我迄今为止尝试过的代码

def validate(date_text):
  try:
    datetime.datetime.strptime(date_text, '%b %d %H:%M')
    return date_text
  except Exception:
    return 'NA'

for i in outputlist:

  cmd = "ls -Altr hpsm_%s.* | tail -n -1 | awk '{print $6,$7,$8,$9'}" % i
  output1 = [commands.getoutput(cmd).split("\n")]



  new_arr = list()
  for out in output1:

      for new_out in out:
          temp_arr = new_out.split("hpsm_")
          temp_arr[0] = validate(temp_arr[0])
          new_arr.append(temp_arr)
  print(new_arr)

使用
pandas

output1=[[Dec 1 03:18 hpsm\u tAlert\u ALL\u oracle\u TBS\u offline.log']]
导入日期时间
作为pd进口熊猫
def验证(日期文本):
尝试:
datetime.datetime.StrTime(日期文本,%b%d%H:%M)
返回日期文本
除例外情况外:
返回“NA”
new_arr=list()
对于输入输出1:
对于新的_out in out:
temp_arr=新的分割(“hpsm”)
临时阵列[0]=验证(临时阵列[0])
新阵列附加(临时阵列)
打印(新建)
df=pd.DataFrame(新的_arr,列=['Alert Name','Status Time'])
打印(df)
#输出
警报名称状态时间
12月0日03:18 tAlert_ALL_oracle_TBS_offline.log

您显示的输出数组格式不正确。您可能需要重新查看您获得的确切输出。否您打印的
output1
内容不正确。请查看
print(output1)
所打印的内容,此处输出动态存储到“output1”。确切地说,它只存储最后一次修改的时间和文件名,就像这样[['Dec 1 03:18 hpsm_tAlert_ALL_oracle_TBS_offline.log']]我在打印“output1”时得到输出,而output1类型是“List”,在尝试下面的代码时我得到输出[['NA',tAlert_ALL_circuit-breaker.log_301219']['NA',tAlert_ALL_load5_Hqchnesos.*:没有这样的文件或目录']['NA',tAlert_ALL_metrics_cpu.log']['NA',tAlert_ALL_metrics_memory_usage.log']['NA',tAlert_ALL_oracle_TBS_offline.log']['NA',tAlert_K8; K8; Kubernetus health.]没有这样的文件或目录[['NA','tAlert\u NN\u WMS\u endpoint-message-count\u MSE.log']]