Py学习  »  Python

Python打印格式建议

Kumar • 4 年前 • 707 次点击  

我想按以下格式打印输出。

echo 'Stats,tableName=test ItemCount=1,TableSizeBytes=85'

我的代码如下。 任何帮助都将不胜感激。

输出:

echo Stats tableName= test ItemCount= 1 TableSizeBytes= 85

代码:

from __future__ import print_function
import boto.dynamodb
import boto

for table in lts:
    tableinfo = conn.describe_table(table)
    TableName = tableinfo['Table']['TableName']
    ItemCount = tableinfo['Table']['ItemCount']
    TableSize = tableinfo['Table']['TableSizeBytes']
    print('echo','Dynamostats','TableName=',TableName,'ItemCount=',ItemCount,'TableSizeBytes=',TableSize)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/57091
 
707 次点击  
文章 [ 3 ]  |  最新文章 4 年前
Henry Harutyunyan
Reply   •   1 楼
Henry Harutyunyan    4 年前

尝试使用

print (f"echo ’Stats,tableName={TableName} ItemCount={ItemCount},TableSizeBytes={TableSize}'")

输出

echo ’Stats,tableName=test ItemCount=1,TableSizeBytes=85'
dcg
Reply   •   2 楼
dcg    4 年前

使用 format

>>> "echo 'Stats,tableName={} ItemCount={},TableSizeBytes={}'".format(TableName, ItemCount, TableSize)
"echo 'Stats,tableName=test ItemCount=1,TableSizeBytes=85'"
>>> 
Prashant Kumar
Reply   •   3 楼
Prashant Kumar    4 年前

试试这个:

print("echo 'Stats,tableName={0} ItemCount={1},TableSizeBytes={2}'".format(TableName, ItemCount, TableSize))

输出:

>>>"echo 'Stats,tableName=test ItemCount=1,TableSizeBytes=85'"