[英]How to print mysql database print style?
我想在python中打印'顯示數據庫'cmd樣式:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
有什么竅門嗎?
import sqlalchemy as sa
insp = sa.inspect(engine)
db_list = insp.get_schema_names()
print(db_list)
表格可以立即使用,請參閱我的示例以及問題表。
import tabulate
example_table = [
{"Database" : "information_schema"},
{"Database" : "mysql"},
{"Database" : "performance_schema"},
{"Database" : "sys"}
]
print(
tabulate.tabulate(
example_table,
headers={
k : v
for k,v in zip(
example_table[0].keys(),
example_table[0].keys()
)
},
tablefmt="psql"
)
)
打印輸出
+--------------------+
| Database |
|--------------------|
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.