2 回答
TA贡献1911条经验 获得超7个赞
或者,您可以使用以下格式打印:
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))
TA贡献1858条经验 获得超8个赞
考虑Python 2.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():
print(",".join([measure, time, players_count, bandwidth]))
编辑2:
使用format():
print("{0},{1},{2},{3}".format(measure,time,players_count,bandwidth))
添加回答
举报