{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to Python \n", "\n", "## Data Persistence with Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "+ #### _file_\n", "+ #### _pickle_\n", "+ #### _dill_\n", "+ #### _json_" ] }, { "cell_type": "code", "execution_count": 117, "metadata": {}, "outputs": [], "source": [ "import os\n", "import pickle\n", "import dill " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## [_file/open_](https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files)\n", "\n", "### open() returns a file object, and is most commonly used with two arguments: open(filename, mode). \n", "\n", "
Mode | \n", "Description | \n", "
---|---|
'r' | \n",
" Open a file for reading. (default) | \n", "
'w' | \n",
" Open a file for writing. Creates a new file if it does not exist or truncates the file if it exists. | \n", "
'x' | \n",
" Open a file for exclusive creation. If the file already exists, the operation fails. | \n", "
'a' | \n",
" Open for appending at the end of the file without truncating it. Creates a new file if it does not exist. | \n", "
't' | \n",
" Open in text mode. (default) | \n", "
'b' | \n",
" Open in binary mode. | \n", "
'+' | \n",
" Open a file for updating (reading and writing) | \n", "