summaryrefslogtreecommitdiff
path: root/Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb
diff options
context:
space:
mode:
authorkinitrupti2015-10-15 17:40:30 +0530
committerkinitrupti2015-10-15 17:40:30 +0530
commit8e4f9ec414f553746330423a974684bbac2163a8 (patch)
tree7d91d4997a3962c3ad62355ad369f7b6b7738ddb /Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb
parent79c8f29f70cc014d5fd8b9900d3c19309134bc1d (diff)
downloadPython-Textbook-Companions-8e4f9ec414f553746330423a974684bbac2163a8.tar.gz
Python-Textbook-Companions-8e4f9ec414f553746330423a974684bbac2163a8.tar.bz2
Python-Textbook-Companions-8e4f9ec414f553746330423a974684bbac2163a8.zip
solved errors
Diffstat (limited to 'Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb')
-rwxr-xr-xPractical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb175
1 files changed, 175 insertions, 0 deletions
diff --git a/Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb b/Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb
new file mode 100755
index 00000000..c25523b7
--- /dev/null
+++ b/Practical_C_Programming/.ipynb_checkpoints/Chapter_14_1-checkpoint.ipynb
@@ -0,0 +1,175 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:aaf3603d1f605477459dd54990dcc4c8c154c9c808805468e92c30fde9487343"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Chapter 14: File input/output"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.1, Page number: 253"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "# Variable declaration\n",
+ "import os\n",
+ "count = 0\n",
+ "in_file = open ('input.txt', 'r')\n",
+ " \n",
+ "# Calculation and result\n",
+ "if not os.path.exists ('input.txt') :\n",
+ " print ('Cannot open input.txt\\n')\n",
+ "\n",
+ "while (1) :\n",
+ " ch = in_file.read(1)\n",
+ " if not ch :\n",
+ " break\n",
+ " count += 1\n",
+ "\n",
+ "print ('Number of characters in input.txt is %d\\n' % count)\n",
+ "\n",
+ "in_file.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Number of characters in input.txt is 0\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.3, Page number: 257"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "# Variable declaration\n",
+ "import sys\n",
+ "import os\n",
+ "in_file = open ('input.txt', 'r')\n",
+ " \n",
+ "# Calculation and result\n",
+ "if not os.path.exists ('input.txt') :\n",
+ " print ('Could not open file\\n')\n",
+ " sys.exit(1)\n",
+ "print ('File found\\n')\n",
+ "\n",
+ "in_file.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "File found\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.4, Page number: 260"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "# Variable declaration\n",
+ "import sys\n",
+ "import os\n",
+ "out_file = open ('test.out', 'w')\n",
+ " \n",
+ "# Calculation and result\n",
+ "if not os.path.exists ('test.out') :\n",
+ " print ('Cannot open output file\\n')\n",
+ " sys.exit(1)\n",
+ "\n",
+ "for cur_char in range (0, 128) :\n",
+ " out_file.write(str (cur_char))\n",
+ " out_file.write('\\n')\n",
+ "\n",
+ "out_file.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 14.5, Page number: 267"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "# Variable declaration\n",
+ "txt_file = open ('input.txt')\n",
+ "\n",
+ "source_content = txt_file.read()\n",
+ "\n",
+ "target = open ('output.txt', 'w')\n",
+ "\n",
+ "# Calculation and result\n",
+ "target.write(source_content)\n",
+ "print ('Content copied')\n",
+ "\n",
+ "target.close()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file