diff options
Diffstat (limited to 'basic_python/files.tex')
-rw-r--r-- | basic_python/files.tex | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/basic_python/files.tex b/basic_python/files.tex index 3646c51..14ee6f6 100644 --- a/basic_python/files.tex +++ b/basic_python/files.tex @@ -10,7 +10,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Title page -\title[Functions]{Python language: reading/writing files} +\title[Files]{Python language: reading/writing files} \author[FOSSEE Team] {The FOSSEE Group} @@ -48,7 +48,7 @@ \end{frame} \begin{frame}[fragile] - \frametitle{Reading the whole file} + \frametitle{Reading the whole file} \begin{lstlisting} In []: pend = f.read() In []: print(pend) @@ -65,6 +65,12 @@ \item \texttt{pend} is a string variable \item We can split it at the newline characters into a list of strings + \end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Closing the file} + \begin{itemize} \item Close the file, when done; Also, if you want to read again \end{itemize} \begin{lstlisting} @@ -73,6 +79,7 @@ \end{lstlisting} \end{frame} + \begin{frame}[fragile] \frametitle{Reading line-by-line} \begin{lstlisting} @@ -159,7 +166,7 @@ In []: line.split() \begin{itemize} \item Original string is split on white-space \item Returns a list of strings - \item It can be given an argument to split on that argrument + \item It can be given an argument to split on that argument \end{itemize} \begin{lstlisting} r = "A;01;JOSE R;083;042;47;AA;72;244;;;" @@ -190,13 +197,10 @@ r.split(';') \end{itemize} \begin{lstlisting} In []: mark_str = "1.25" - In []: mark = int(mark_str) + In []: mark = float(mark_str) In []: type(mark_str) In []: type(mark) \end{lstlisting} - \begin{itemize} - \item \texttt{strip} is returning a new string - \end{itemize} \end{frame} \begin{frame}[fragile, plain] @@ -246,6 +250,7 @@ for line in open("sslc1.txt"): \begin{frame}[fragile, plain] \frametitle{File parsing -- debugging} + \small \begin{lstlisting} math_B = [] # empty list to store marks for i, line in enumerate(open("sslc1.txt")): |