最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python json格式化打印實(shí)現(xiàn)過(guò)程解析

 更新時(shí)間:2020年07月21日 09:17:22   作者:捷后愚生  
這篇文章主要介紹了Python json格式化打印實(shí)現(xiàn)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

編寫python腳本,調(diào)試的時(shí)候需要打印json格式報(bào)文,直接打印看不出層次,可以使用json.dumps格式化打印

import json
import requests

def test_json():
  r=requests.get('https://home.testing-studio.com/categories.json')
  print(r.json())
  print(json.dumps(r.json(), indent=2,ensure_ascii=False)) # r.json()是json對(duì)象,indent表示縮進(jìn),ensure_ascii設(shè)置編碼
格式化打印前:

格式化打印前:

格式化打印后:

json.dumps方法源碼:

def dumps(obj, *, skipkeys=False, ensure_ascii=True, check_circular=True,
    allow_nan=True, cls=None, indent=None, separators=None,
    default=None, sort_keys=False, **kw):
  """Serialize ``obj`` to a JSON formatted ``str``.

  If ``skipkeys`` is true then ``dict`` keys that are not basic types
  (``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
  instead of raising a ``TypeError``.

  If ``ensure_ascii`` is false, then the return value can contain non-ASCII
  characters if they appear in strings contained in ``obj``. Otherwise, all
  such characters are escaped in JSON strings.

  If ``check_circular`` is false, then the circular reference check
  for container types will be skipped and a circular reference will
  result in an ``OverflowError`` (or worse).

  If ``allow_nan`` is false, then it will be a ``ValueError`` to
  serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
  strict compliance of the JSON specification, instead of using the
  JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).

  If ``indent`` is a non-negative integer, then JSON array elements and
  object members will be pretty-printed with that indent level. An indent
  level of 0 will only insert newlines. ``None`` is the most compact
  representation.

  If specified, ``separators`` should be an ``(item_separator, key_separator)``
  tuple. The default is ``(', ', ': ')`` if *indent* is ``None`` and
  ``(',', ': ')`` otherwise. To get the most compact JSON representation,
  you should specify ``(',', ':')`` to eliminate whitespace.

  ``default(obj)`` is a function that should return a serializable version
  of obj or raise TypeError. The default simply raises TypeError.

  If *sort_keys* is true (default: ``False``), then the output of
  dictionaries will be sorted by key.

  To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
  ``.default()`` method to serialize additional types), specify it with
  the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.

  """
  # cached encoder
  if (not skipkeys and ensure_ascii and
    check_circular and allow_nan and
    cls is None and indent is None and separators is None and
    default is None and not sort_keys and not kw):
    return _default_encoder.encode(obj)
  if cls is None:
    cls = JSONEncoder
  return cls(
    skipkeys=skipkeys, ensure_ascii=ensure_ascii,
    check_circular=check_circular, allow_nan=allow_nan, indent=indent,
    separators=separators, default=default, sort_keys=sort_keys,
    **kw).encode(obj)

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python可視化神器pyecharts繪制折線圖詳情

    Python可視化神器pyecharts繪制折線圖詳情

    這篇文章主要介紹了Python可視化神器pyecharts繪制折線圖詳情,折線圖和柱狀圖一樣是我們?nèi)粘?梢暬疃嗟囊粋€(gè)圖例,當(dāng)然它的優(yōu)勢(shì)和適用場(chǎng)景相信大家肯定不陌生,要想快速的得出趨勢(shì),抓住趨勢(shì)二字,就會(huì)很快的想到要用折線圖來(lái)表示了
    2022-07-07
  • Django項(xiàng)目中表的查詢的操作

    Django項(xiàng)目中表的查詢的操作

    這篇文章主要介紹了Django項(xiàng)目中表的查詢的操作,文中給大家提到了Django項(xiàng)目 ORM常用的十三種查詢方法,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • CentOS 7下安裝Python3.6 及遇到的問(wèn)題小結(jié)

    CentOS 7下安裝Python3.6 及遇到的問(wèn)題小結(jié)

    這篇文章主要介紹了CentOS 7下安裝Python3.6 及遇到的問(wèn)題小結(jié),需要的朋友可以參考下
    2018-11-11
  • 解決pytorch rnn 變長(zhǎng)輸入序列的問(wèn)題

    解決pytorch rnn 變長(zhǎng)輸入序列的問(wèn)題

    這篇文章主要介紹了解決pytorch rnn 變長(zhǎng)輸入序列的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • 使用python將圖片格式轉(zhuǎn)換為ico格式的示例

    使用python將圖片格式轉(zhuǎn)換為ico格式的示例

    今天小編就為大家分享一篇使用python將圖片格式轉(zhuǎn)換為ico格式的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-10-10
  • Python中計(jì)算相似度的方法詳解

    Python中計(jì)算相似度的方法詳解

    計(jì)算相似度是許多機(jī)器學(xué)習(xí)和數(shù)據(jù)分析任務(wù)中的重要步驟,尤其是在推薦系統(tǒng)、文本分析和圖像處理等領(lǐng)域,下面我們就來(lái)看看具體的實(shí)現(xiàn)方法吧
    2025-02-02
  • python3爬取數(shù)據(jù)至mysql的方法

    python3爬取數(shù)據(jù)至mysql的方法

    這篇文章主要為大家詳細(xì)介紹了python3爬取數(shù)據(jù)至mysql的方法 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Python Tkinter基礎(chǔ)控件用法

    Python Tkinter基礎(chǔ)控件用法

    這篇文章主要介紹了Python Tkinter基礎(chǔ)控件用法,包括窗口的顯示、顯示內(nèi)置圖片、彈出窗口、菜單等等,需要的朋友可以參考下
    2014-09-09
  • Python中有趣在__call__函數(shù)

    Python中有趣在__call__函數(shù)

    這篇文章主要介紹了Python中有趣在__call__函數(shù),本文直接給出一個(gè)使用實(shí)例,以此來(lái)講解__call__函數(shù)的用法,需要的朋友可以參考下
    2015-06-06
  • python調(diào)用百度通用翻譯API的方法實(shí)現(xiàn)

    python調(diào)用百度通用翻譯API的方法實(shí)現(xiàn)

    本文主要介紹了python調(diào)用百度通用翻譯API的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2025-01-01

最新評(píng)論

如东县| 秀山| 淳化县| 海城市| 余干县| 集安市| 罗平县| 高要市| 莆田市| 阿鲁科尔沁旗| 高密市| 张家川| 肇源县| 军事| 济阳县| 渝中区| 运城市| 固阳县| 贵州省| 赤水市| 兴化市| 沈阳市| 玉门市| 大宁县| 丽江市| 砚山县| 南靖县| 缙云县| 安吉县| 上蔡县| 婺源县| 安泽县| 襄樊市| 娄底市| 新河县| 锦屏县| 东方市| 皮山县| 新沂市| 凤冈县| 白河县|