我如何使用python和yaml生成报告以清除通过运行vsql查询生成的输出

时间:2019-06-19 02:23:36

标签: python yaml

在vertica VSQL上运行python脚本以生成SQL数据统计信息。该报告随附[!! python / unicode我的问题如何清除脚本,以便结果以简洁的方式显示。

结果:

!!python/object/apply:collections.OrderedDict
  - - - !!python/unicode 'host_name'
      - !!python/object/new:future.types.newstr.newstr [!!python/unicode 'xx.xx.x.xx']
    - [!!python/unicode 'processor_count', 1]
    - [!!python/unicode 'processor_core_count', 8]
    - - !!python/unicode 'processor_description'
      - !!python/object/new:future.types.newstr.newstr [!!python/unicode 'Intel(R)
          Xeon(R) CPU E5-2673 v3 @ 2.40GHz']
- !!python/object/apply:collections.OrderedDict
  - - - !!python/unicode 'host_name'
      - !!python/object/new:future.types.newstr.newstr [!!python/unicode ''xx.xx.x.xx'']
    - [!!python/unicode 'processor_count', 1]
    - [!!python/unicode 'processor_core_count', 8]
    - - !!python/unicode 'processor_description'
      - !!python/object/new:future.types.newstr.newstr [!!python/unicode 'Intel(R)
          Xeon(R) CPU E5-2673 v3 @ 2.40GHz']

不能删除[!! python / unicode,我只需要列名和输出,例如如何生成oracle sql报告。

代码:

yaml_str_pros = """------- Vertica Processor information -------------------------------------------  """
print yaml_str_pros
def run_query3(conn, query):
  cur = conn.cursor('dict')
  ret = cur.execute(query).fetchall()
  return ret
x3 = run_query3(connection, '''SELECT /*+label(diag_cpu_info)*/  host_name, processor_count,processor_core_count,processor_description from v_monitor.host_resources;''' )
#print x3
yaml.dump(x3,sys.stdout)

不熟悉yaml,对任何帮助点都非常重视。

0 个答案:

没有答案