getting-started-files/script.rst
changeset 345 d82151cc11f5
parent 245 3ed6ef2ea91f
child 379 4b3c0d8fffe2
equal deleted inserted replaced
344:700785318ed2 345:d82151cc11f5
    13 .. 1. getting started with ipython
    13 .. 1. getting started with ipython
    14 .. #. getting started with lists
    14 .. #. getting started with lists
    15 .. #. getting started with for
    15 .. #. getting started with for
    16      
    16      
    17 .. Author              : Puneeth
    17 .. Author              : Puneeth
    18    Internal Reviewer   : 
    18    Internal Reviewer   : Anoop Jacob Thomas<anoop@fossee.in>
    19    External Reviewer   :
    19    External Reviewer   :
    20    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
    20    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
    21 
    21 
    22 Script
    22 Script
    23 ------
    23 ------
    75 
    75 
    76   pend
    76   pend
    77 
    77 
    78 Following is an exercise that you must do. 
    78 Following is an exercise that you must do. 
    79 
    79 
       
    80 .. #[[Anoop:add context switch to next slide - questions]]
       
    81 
    80 %%1%% Split the variable into a list, ``pend_list``, of the lines in
    82 %%1%% Split the variable into a list, ``pend_list``, of the lines in
    81 the file. Hint, use the tab command to see what methods the string
    83 the file. Hint, use the tab command to see what methods the string
    82 variable has.
    84 variable has.
    83 
    85 
    84 Please, pause the video here. Do the exercise and then continue. 
    86 Please, pause the video here. Do the exercise and then continue. 
    85 
    87 
    86 .. #[punch: should this even be put? add dependency to strings LO,
    88 .. #[punch: should this even be put? add dependency to strings LO,
    87 .. where we mention that strings have methods for manipulation. hint:
    89 .. where we mention that strings have methods for manipulation. hint:
    88 .. use splitlines()]
    90 .. use splitlines()]
    89 
    91 
       
    92 .. #[[Anoop: let us have it here, let us consider this as a
       
    93    refresher]]
       
    94 
       
    95 .. #[[Anoop:add context switch to next slide - solution]]
       
    96 
    90 ::
    97 ::
    91 
    98 
    92   pend_list = pend.splitlines()
    99   pend_list = pend.splitlines()
    93 
   100 
    94   pend_list
   101   pend_list
    97 will have to close the file, since the file has already been read till
   104 will have to close the file, since the file has already been read till
    98 the end.
   105 the end.
    99 
   106 
   100 .. #[punch: should we mention file-pointer?]
   107 .. #[punch: should we mention file-pointer?]
   101 
   108 
       
   109 .. #[[Anoop: I think we can say that ``f`` is a file pointer which
       
   110    points to the next line/data to be read from the file. We could
       
   111    skip details.]]
       
   112 
   102 Let us close the file opened into f.
   113 Let us close the file opened into f.
   103 ::
   114 ::
   104 
   115 
   105   f.close()
   116   f.close()
   106 
   117 
   136       print line
   147       print line
   137 
   148 
   138 As we already know, ``line`` is just a dummy variable, and not a
   149 As we already know, ``line`` is just a dummy variable, and not a
   139 keyword. We could have used any other variable name, but ``line``
   150 keyword. We could have used any other variable name, but ``line``
   140 seems meaningful enough.
   151 seems meaningful enough.
       
   152 
       
   153 .. #[[Anoop: using dummy variable doesn't seem correct, can say line
       
   154    is a variable]]
   141 
   155 
   142 Instead of just printing the lines, let us append them to a list,
   156 Instead of just printing the lines, let us append them to a list,
   143 ``line_list``. We first initialize an empty list, ``line_list``. 
   157 ``line_list``. We first initialize an empty list, ``line_list``. 
   144 ::
   158 ::
   145 
   159 
   165 Notice that ``line_list`` is a list of the lines in the file, along
   179 Notice that ``line_list`` is a list of the lines in the file, along
   166 with the newline characters. If you noticed, ``pend_list`` did not
   180 with the newline characters. If you noticed, ``pend_list`` did not
   167 contain the newline characters, because the string ``pend`` was
   181 contain the newline characters, because the string ``pend`` was
   168 split on the newline characters. 
   182 split on the newline characters. 
   169 
   183 
       
   184 .. #[[Anoop: I think we need to tell them that each line can be
       
   185    stripped and appended to list to avoid the problem of newline
       
   186    characters.]]
       
   187 
       
   188 .. #[[Anoop: I think the code that are required to be typed can be
       
   189    added to the slide.]]
       
   190 
       
   191 .. #[[Anoop: Context switches are to be added.]]
       
   192 
   170 {{{ show the summary slide }}}
   193 {{{ show the summary slide }}}
   171 
   194 
   172 That brings us to the end of this tutorial. In this tutorial we
   195 That brings us to the end of this tutorial. In this tutorial we
   173 have learnt to open and close files, read the data in the files as
   196 have learnt to open and close files, read the data in the files as
   174 a whole, using the read command or reading it line by line by
   197 a whole, using the read command or reading it line by line by