getting-started-files/quickref.tex
author anand
Mon, 15 Nov 2010 14:31:42 +0530
changeset 498 4255f995a40c
parent 285 7c4855fb8e5f
permissions -rw-r--r--
checklist not OK; one more long answer question has to be included.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
285
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     1
\textbf{Getting Started -- files}
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     2
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     3
\lstinline|f = open('filename')| returns a file object. \lstinline|f|
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     4
can be used to perform further operations on the file. 
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
285
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     6
\lstinline|f.read()| reads the whole file and returns the contents. 
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     7
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     8
\lstinline|f.close()| closes the file. 
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
285
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    10
\lstinline|for line in open('filename'):| -- iterate over the file
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    11
line-by-line. 
7c4855fb8e5f Quickrefs
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    12