简体   繁体   English

并排打印值

[英]Print values side by side

I am trying to output the values side by side. 我试图并排输出值。 I have pasted the example and code of what I am trying to accomplish. 我已经粘贴了我想要完成的示例和代码。 Is this possible? 这可能吗?

import requests
import json

r = requests.get('https://api.website.com',headers = {"content-type": "application/json", "X-Auth-Key":"key-here","X-Auth-Email":"email@"})

#packages_json = r.json()
#packages_list = json.dumps(packages_json, indent=2)



with open("C:\\Users\\vm\\Desktop\\newjson.json") as access_json:
#   print(packages_list, file = access_json)
#   data = pd.read_json(access_json)
#   print(data)
    read_content = json.load(access_json)
#print(read_content)


#for i in range(0,len(read_content['result']['totals'])):

unique = read_content['result']['totals']['uniques']['all']
requests = read_content['result']['totals']['requests']['all']
print("Unique Visitors " + str(unique))
print("Total Requests " + str(requests))

what I want it to look like: 我希望它看起来像:

Unique Visitors 862 next-value1 next-value2 next-value3

Total Requests 2866 next-value1 next-value2 next-value3

Basically, it's reading the value from the json file which is fetching the data from the API on an hourly basis. 基本上,它正在读取json文件中的值,该文件每小时从API获取数据。 What I am trying to accomplish is that the script run every hour and look into the file and fetch whatever the current value place it next to the existing value. 我想要完成的是脚本每小时运行并查看文件并获取当前值放在现有值旁边的任何值。

If the unique variable is a list you could do: 如果unique变量是一个列表,您可以这样做:

print("Unique Visitors " + '   '.join(unique))

But you'll be better off using the logging module so it will go to a specific log file in the format you want. 但是您最好使用日志记录模块,以便以您想要的格式转到特定的日志文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM