|
1 % Created 2010-10-21 Thu 14:35 |
|
2 \documentclass[presentation]{beamer} |
|
3 \usepackage[latin1]{inputenc} |
|
4 \usepackage[T1]{fontenc} |
|
5 \usepackage{fixltx2e} |
|
6 \usepackage{graphicx} |
|
7 \usepackage{longtable} |
|
8 \usepackage{float} |
|
9 \usepackage{wrapfig} |
|
10 \usepackage{soul} |
|
11 \usepackage{t1enc} |
|
12 \usepackage{textcomp} |
|
13 \usepackage{marvosym} |
|
14 \usepackage{wasysym} |
|
15 \usepackage{latexsym} |
|
16 \usepackage{amssymb} |
|
17 \usepackage{hyperref} |
|
18 \tolerance=1000 |
|
19 \usepackage[english]{babel} \usepackage{ae,aecompl} |
|
20 \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} |
|
21 \usepackage{listings} |
|
22 \lstset{language=Python, basicstyle=\ttfamily\bfseries, |
|
23 commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, |
|
24 showstringspaces=false, keywordstyle=\color{blue}\bfseries} |
|
25 \providecommand{\alert}[1]{\textbf{#1}} |
|
26 |
|
27 \title{Getting started with files} |
|
28 \author{FOSSEE} |
|
29 \date{} |
|
30 |
|
31 \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} |
|
32 \begin{document} |
|
33 |
|
34 \maketitle |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 \begin{frame} |
|
45 \frametitle{Outline} |
|
46 \label{sec-1} |
|
47 |
|
48 \begin{itemize} |
|
49 \item Opening and reading contents of a file |
|
50 \item Closing open files |
|
51 \item Reading all the contents of the file at once |
|
52 \item Reading files line by line |
|
53 \end{itemize} |
|
54 \end{frame} |
|
55 \begin{frame} |
|
56 \frametitle{Question 1} |
|
57 \label{sec-2} |
|
58 |
|
59 Split the variable into a list, \texttt{pend\_list}, of the lines in the |
|
60 file. Hint, use the tab command to see what methods the string |
|
61 variable has. |
|
62 \end{frame} |
|
63 \begin{frame}[fragile] |
|
64 \frametitle{Solution 1} |
|
65 \label{sec-3} |
|
66 |
|
67 \begin{verbatim} |
|
68 In []: pend_list = pend.splitlines() |
|
69 |
|
70 In []: pend_list |
|
71 \end{verbatim} |
|
72 \end{frame} |
|
73 \begin{frame} |
|
74 \frametitle{Question 2} |
|
75 \label{sec-4} |
|
76 |
|
77 Re-open the file \texttt{pendulum.txt} with \texttt{f} as the file object. |
|
78 \end{frame} |
|
79 \begin{frame}[fragile] |
|
80 \frametitle{Solution 2} |
|
81 \label{sec-5} |
|
82 |
|
83 \begin{verbatim} |
|
84 In []: f = open('/home/fossee/pendulum.txt') |
|
85 \end{verbatim} |
|
86 \end{frame} |
|
87 \begin{frame} |
|
88 \frametitle{Summary} |
|
89 \label{sec-6} |
|
90 |
|
91 \begin{itemize} |
|
92 \item Opening a file using \texttt{open} function |
|
93 \item Reading all the contents of the file at once using \texttt{read()} method |
|
94 \item Closing open files using the \texttt{close} method |
|
95 \item Reading files line by line by iterating using a \texttt{for} loop |
|
96 \end{itemize} |
|
97 \end{frame} |
|
98 \begin{frame} |
|
99 \frametitle{Thank you!} |
|
100 \label{sec-7} |
|
101 |
|
102 \begin{block}{} |
|
103 \begin{center} |
|
104 This spoken tutorial has been produced by the |
|
105 \textcolor{blue}{FOSSEE} team, which is funded by the |
|
106 \end{center} |
|
107 \begin{center} |
|
108 \textcolor{blue}{National Mission on Education through \\ |
|
109 Information \& Communication Technology \\ |
|
110 MHRD, Govt. of India}. |
|
111 \end{center} |
|
112 \end{block} |
|
113 \end{frame} |
|
114 |
|
115 \end{document} |