Loading topic
open(). Two settings in that call, encoding and newline, cause most of the bugs people hit later. This chapter explains what they do and which values to choose.3 min readjson functions that do the conversion.3 min readwith statement, and how to catch exceptions. It covers the four core functions of the json module and the mistakes people make with them most often.3 min readjson.dumps and json.dump, open files with with, and read a short traceback. By default, json.dumps produces valid but hard-to-read text. Three keyword arguments change that: indent, sort_keys, and ensure_ascii. A fourth, separators, controls whitespa3 min readjson.load and json.loads, use with to open files, and write try/except blocks. It covers what happens when the input is not valid JSON and how to report that cleanly.2 min readjson.dumps and json.dump, write functions, and catch exceptions. It builds on the earlier chapters about the JSON data model and about reading and writing JSON.3 min readwith statement, and how to handle exceptions. It builds on the previous chapter on opening files safely, because the csv module depends on how you open the file.3 min readwith statement, and how csv.reader and csv.writer work. You should also know why CSV files are opened with newline="" and an explicit encoding.3 min readwith, write functions, handle exceptions, and read a CSV file with csv.DictReader. If not, review those topics first.2 min readcsv.reader and csv.writer. It also assumes you know to open CSV files with newline="" and an explicit encoding. Here you will learn how to handle CSV variants that use other separators or quoting rules.3 min readwith, use dicts and lists, and catch exceptions. It also assumes you know csv.DictReader, csv.DictWriter, json.load, and json.dump from earlier chapters. Here you combine them to move data between the two formats in both directions.3 min readwith, use json.loads and json.dumps, and read CSV with csv.reader and DictReader. It also assumes you know how functions and exceptions work.3 min read