Python Print format suggestion

Viewed 86

I am using python2 for printing some data. I am looking to print the output in the following format.

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

With my code it is giving in the below format. Any Help would be appreciated.

Ouput:

echo Stats tableName= test ItemCount= 1 TableSizeBytes= 85

Code:

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)
3 Answers

Use format like the following to get the result you want:

>>> "echo 'Stats,tableName={} ItemCount={},TableSizeBytes={}'".format(TableName, ItemCount, TableSize)
"echo 'Stats,tableName=test ItemCount=1,TableSizeBytes=85'"
>>> 

Try this :

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

Output :

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

Try using

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

Output

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