在python中打印不带引号的字符串、int和time

在python中打印不带引号的字符串、int和time,python,python-2.7,Python,Python 2.7,我有四个变量:- measure = 'domain.bandwidth' (string type) time = datetime.datetime.now() (datetime type) players_count = 50 (int type) bandwidth = 3672782 (int type) 现在我想在CLI上打印,如下所示:- domain.bandwidth,time=2020-08-28 17:55:55.567057,players_count=50,band

我有四个变量:-

measure = 'domain.bandwidth' (string type)
time = datetime.datetime.now() (datetime type)
players_count = 50 (int type)
bandwidth = 3672782 (int type)
现在我想在CLI上打印,如下所示:-

domain.bandwidth,time=2020-08-28 17:55:55.567057,players_count=50,bandwidth=3672782
不应该有引号或任何输出必须严格像上面一样


我正在使用python 2.7,并试图避免使用任何外部库。

考虑python2.x

一种方法是将它们全部强制转换为类型
str
,然后使用
连接:

import datetime
measure = 'domain.bandwidth' # (string type)
time = str(datetime.datetime.now()) # (datetime type)
players_count = str(50) # (int type)
bandwidth = str(3672782)  # (int type)
x = measure + "," + time + "," + players_count + "," + bandwidth
print(x)
输出:

domain.bandwidth,2020-08-29 00:12:49.396197,50,3672782
编辑

使用
join()

编辑2

使用
格式()


或者,您可以使用以下格式化打印:

import datetime

measure = 'domain.bandwidth'
time = datetime.datetime.now()
players_count = 50
bandwidth = 3672782

print('%s,time=%s,players_count=%s,bandwidth=%s'
        % (measure, time.strftime('%Y-%M-%d %H:%I:%S.%f'), players_count, bandwidth))

输出应该是domain.bandwidth,time=2020-08-28 17:55:55.567057,players_count=50,bandwidth=3672782Hey@Ivan我如何更新它以给出类似domain.bandwidth time=2020-20-2316:04:53.429618,last_minute_总计_players=286,last_minute_outgoing_bandwidth_bytes=3999073基本上是domain.bandwidth和timeHi@abhi之间的一个空白,只需在那里放一个空格。如
“%s,时间=%s…”
print("{0},{1},{2},{3}".format(measure,time,players_count,bandwidth))
import datetime

measure = 'domain.bandwidth'
time = datetime.datetime.now()
players_count = 50
bandwidth = 3672782

print('%s,time=%s,players_count=%s,bandwidth=%s'
        % (measure, time.strftime('%Y-%M-%d %H:%I:%S.%f'), players_count, bandwidth))