Added snippet to read and write utf-8.

This commit is contained in:
Donne Martin 2015-02-16 17:01:10 -05:00
parent 4af62400e3
commit 8b974b811a

View File

@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:c7a4bcb2e55f64b6c49581b50c190fa5f6742f215ee7c4e3a6d10b11319a56fb"
"signature": "sha256:c535c4eb558966d14a178dfbd21918ecadc105f12b3c5f939ebf807d5afd1e6f"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -16,7 +16,8 @@
"\n",
"* Open a File for Reading\n",
"* Read a File\n",
"* Write to a New File"
"* Write to a New File\n",
"* Read and write UTF-8"
]
},
{
@ -38,7 +39,7 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
"prompt_number": 2
},
{
"cell_type": "markdown",
@ -90,7 +91,7 @@
]
}
],
"prompt_number": 2
"prompt_number": 3
},
{
"cell_type": "markdown",
@ -113,7 +114,29 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Read and Write UTF-8"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import codecs\n",
"with codecs.open(\"hello_world_new.txt\", \"a\", \"utf-8\") as new_file:\n",
" with codecs.open(\"hello_world.txt\", \"r\", \"utf-8\") as old_file: \n",
" for line in old_file:\n",
" new_file.write(line + '\\n')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
}
],
"metadata": {}