0

I am passing a file object as an argument to a function in Python. Inside this function I want to read the content of the file passed as an argument.

Will I be able to read the file from the beginning or will it continue from the last line read before passing it to the current function ?

G4bri3l
  • 4,996
  • 4
  • 31
  • 53

4 Answers4

6

This is something you could easily find out yourself by testing. The filehandle remembers it's current line so it will continue reading where it left of.

Lawrence Benson
  • 1,398
  • 1
  • 16
  • 33
  • 1
    I wish I could upvote this answer twice or more - why do people waiste everyone's time asking questions they could answer by themselves in less time than they spent posting the question, I really wonder... – bruno desthuilliers Jun 26 '15 at 19:01
0

File objects are generators, so they will continue from the next line.

Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70
0

I haven't coded in python much, but I would assume that the parameter you passed in is actually a reference to the object, which means that it should read from the next line. See this post for clarification.

Community
  • 1
  • 1
Speerian
  • 1,138
  • 1
  • 12
  • 29
0

You might find https://docs.python.org/2/tutorial/inputoutput.html#methods-of-file-objects helpful. The file object keeps track of where it is.