The difference between Python json.dumps () json.dump ()

Source: Internet
Author: User

See the code example first

In [1]: a = {' A ': ' abc ', ' B ': ' BCD '}in [2]: in [2]: Import Jsonin [3]: Print Json.dumps (a) {"A": "abc", "B": "BCD"}in [4]: Print Json.dump (a)---------------------------------------------------------------------------TypeError                                 Traceback (most recent) <ipython-input-4-68d925ef8846> in <module> ()----> 1 print json.dump (a) Typeerror:dump () takes at least 2 arguments (1 given)

  

Dumps (obj, Skipkeys=false, Ensure_ascii=true, Check_circular=true, Allow_nan=true, Cls=none, Indent=None, separators= None, encoding= ' Utf-8 ', Default=none, Sort_keys=false, **kw)
Serialize ' obj ' to a JSON formatted ' str '.

Dump (obj, FP, Skipkeys=false, Ensure_ascii=true, Check_circular=true, Allow_nan=true, Cls=none, Indent=none, Separators=none, encoding= ' Utf-8 ', Default=none, Sort_keys=false, **kw)
Serialize ' obj ' as a JSON formatted stream to ' FP ' (a
". Write ()"-supporting File-like object).

Simply put, dump gives you something that is similar to a file pointer (not a real pointer), which can be combined with a file operation, and dumps directly to Str.

In practice, dump is seldom used.

The difference between Python json.dumps () json.dump ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.