Updated cheatsheet of session 2 day 1.
authorSantosh G. Vattam <vattam.santosh@gmail.com>
Wed, 18 Nov 2009 19:26:48 +0530
changeset 314 c9f05808e1c4
parent 313 f5bcb974a665
child 315 141f3903d4e8
Updated cheatsheet of session 2 day 1.
day1/cheatsheet2.tex
--- a/day1/cheatsheet2.tex	Wed Nov 18 18:37:15 2009 +0530
+++ b/day1/cheatsheet2.tex	Wed Nov 18 19:26:48 2009 +0530
@@ -124,15 +124,24 @@
 A string can be split based on the delimiter specified within quotes. A combination of more than one delimiter can also be used.\\
 \typ{In []: greet.split(', ')}\\
 \typ{Out[]: ['hello', 'world']}\\Note the whitespace is not there anymore.
-
+\newpage
 \section{Plotting from Files}
-\subsection{Opening, reading and writing files}
+\subsection{Opening files}
+
+\typ{In []: f = open('datafile.txt')}\\By default opens in read mode. \\If file does not exist then it throws an exception\\
+\typ{In []: f = open('datafile.txt','r')}\\Specifying the read mode\\
+\typ{In []: f = open('datafile.txt', 'w')}\\Opens the file in write mode. \\If the file already exists, then it deletes all the previous content and opens.
+
+\subsection{Reading from files}
+Just like lists files are iterable as well.
 
 \begin{lstlisting}
-  In []: f = open('datafile.txt') #By default opens in read mode. If file does not exist then it throws an exception
-  In []: f = open('datafile.txt','r') #Specifying the read mode
-  In []: f = open('datafile.txt', 'w') #Opens the file in write mode. If the file already exists, then it deletes all the previous content and opens.
+  In []: for line in f:
+    ...:     print line
+    ...: 
+    ...:
 \end{lstlisting}
+
 \subsection{Plotting}
 \begin{lstlisting}
 l = []