{ "metadata": { "name": "chapter-13.ipynb" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

Chapter 13: More Issues In Input/Output

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Using argc and argv, Page number: 467

" ] }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "import sys\n", "\n", "if ( len(sys.argv) != 3 ):\n", " print ( \"Improper number of arguments\" )\n", " exit( )\n", " \n", "fs = open ( sys.argv[2], \"r\" ) #open file in read mode\n", "if ( not fs):\n", " print ( \"Cannot open source file\" )\n", " exit( )\n", " \n", "ft = open ( sys.argv[2], \"w\" ) #open file in write mode\n", "if ( not ft ):\n", " print ( \"Cannot open target file\" )\n", " fs.close()\n", " exit( )\n", " \n", "while ( 1 ):\n", " ch = fs.read(1)\n", " if ( not ch ):\n", " break\n", " else:\n", " ft.write(ch)\n", "\n", "#close files \n", "fs.close()\n", "ft.close()\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Improper number of arguments\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }