Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
02c64d56
Commit
02c64d56
authored
Jun 28, 2005
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Note that files are iterable.
parent
5a34afb7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
Doc/tut/tut.tex
Doc/tut/tut.tex
+15
-0
No files found.
Doc/tut/tut.tex
View file @
02c64d56
...
...
@@ -3166,6 +3166,21 @@ entire file in memory. Only complete lines will be returned.
[
'This is the first line of the file.
\n
', 'Second line of the file
\n
'
]
\end
{
verbatim
}
An alternate approach to reading lines is to loop over the file object.
This is memory efficient, fast, and leads to simpler code:
\begin
{
verbatim
}
>>> for line in f:
print line,
This is the first line of the file.
Second line of the file
\end
{
verbatim
}
The alternative approach is simpler but does not provide as fine
-
grained
control. Since the two approaches manage line buffering differently,
they should not be mixed.
\code
{
f.write
(
\var
{
string
}
)
}
writes the contents of
\var
{
string
}
to
the file, returning
\code
{
None
}
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment