繁体   English   中英

在终端 Visual Studio Code 中看起来更漂亮的 output

[英]Nicer looking output in the terminal Visual Studio Code

有什么方法可以使 Visual Studio Code Python 终端中的 output 更具可读性?

这是从我的 Twitch 频道抓取信息后终端的样子:

{"docs":[{"donation":{"user":{"username":"Mrrobotsan","geo":"SE","email":"christopher.wallenskog@hotmail.com"},"media":{"start":0,"videoId":""},"message":"Sorry for delayed dono, but you truly are the most beautiful streamer 
in da wolrdo... with very sexy haircut, pls send dm ;D","amount":5,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5f5fbc48d8f39ac6c71397f6","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-09-14T18:54:00.526Z","updatedAt":"2020-09-14T18:54:12.992Z","token":"EC-41X07702TH3551025","transactionId":"6U238320601573020"},{"donation":{"user":{"username":"Mrrobotsan","geo":"SE","email":"christopher.wallenskog@hotmail.com"},"media":{"start":0,"videoId":""},"message":"Sorry for delay best streamer, with very sexy haircut, send dm pls ;D","amount":5,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5f5fbb8cf2b37c417bb01c3d","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-09-14T18:50:52.318Z","updatedAt":"2020-09-14T18:53:05.455Z","token":"EC-8UL51613AG332564X","transactionId":"22865708CK4171210"},{"donation":{"user":{"username":"teusz","geo":"SE","email":"mateuszcwiklinski477@gmail.com"},"media":{"start":0,"videoId":""},"message":"0.01 mer","amount":2.38,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5f380c203080e933fe587df3","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-08-15T16:24:00.463Z","updatedAt":"2020-08-15T16:24:35.235Z","token":"EC-6P934493F4731022M","transactionId":"04L1807548587344C"},{"donation":{"user":{"username":"Ami","geo":"FI","email":"viljamny@gmail.com"},"media":{"start":0,"videoId":""},"message":".","amount":2.37,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5f380ba85fdb306bfe259ff1","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-08-15T16:22:00.389Z","updatedAt":"2020-08-15T16:23:07.153Z","token":"EC-15580574R0466603T","transactionId":"97G82573V6280833C"},{"donation":{"user":{"username":"Christaffa","geo":"SE","email":"ridleygaming99@gmail.com"},"media":{"start":0,"videoId":""},"message":"Here is a little present for a guy called chriss","amount":10.67,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5e8f74f11b28cc7a262ff0e8","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-04-09T19:18:09.696Z","updatedAt":"2020-04-09T19:18:59.647Z","token":"EC-6V721718BM2027504","transactionId":"73U09025KT621953P"},{"donation":{"user":{"username":"totally the real keppy","geo":"NL","email":"shailin.ace@gmail.com"},"media":{"start":0,"videoId":""},"message":"some money to feed your gambling addiction","amount":1,"currency":"USD","paymentMethod":null},"provider":"paypal","status":"success","deleted":false,"_id":"5e80dc7e593906478b99a4b2","channel":"5df7fa895b5f7e4344abf280","approved":"allowed","createdAt":"2020-03-29T17:35:58.359Z","updatedAt":"2020-03-29T17:36:23.724Z","token":"EC-03X58148UE739170L","transactionId":"8SF26109BV8270519"}],"total":6,"limit":25,"offset":0}

如果可能的话,我希望它看起来更接近这个:我希望终端 output 看起来像的图片

Copy the output of that dictionary and paste it into https://jsonformatter.curiousconcept.com/ and it will give you a nicely formatted JSON object like the one you have in the picture.

另外,删除第一张图片,并将 output 粘贴到代码块中。

看起来你有一个 JSON 字符串。 您可以使用json.loads来获取 python 字典。 然后,您可以使用json.dumps和 indent=4 来获得缩进良好的字符串表示。

>>> import json
>>> s = '{"first_name": "Justin", "last_name": "Ezequiel", "company_name": "", "address": "5665 McLaughlin ", "city": "Mississauga", "province": "ON", "postal_code": "L5R 3K5", "country": "CA", "phone_number": "", "shipping_cost": "0.00"}'
>>> print(s)
{"first_name": "Justin", "last_name": "Ezequiel", "company_name": "", "address": "5665 McLaughlin ", "city": "Mississauga", "province": "ON", "postal_code": "L5R 3K5", "country": "CA", "phone_number": "", "shipping_cost": "0.00"}
>>> o = json.loads(s)
>>> print(json.dumps(o, indent=4))
{
    "first_name": "Justin",
    "last_name": "Ezequiel",
    "company_name": "",
    "address": "5665 McLaughlin ",
    "city": "Mississauga",
    "province": "ON",
    "postal_code": "L5R 3K5",
    "country": "CA",
    "phone_number": "",
    "shipping_cost": "0.00"
}

暂无
暂无

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

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