[Tutor] Question about reading from a file.
Mark Lawrence
breamoreboy at yahoo.co.uk
Tue Aug 7 11:12:36 CEST 2012
On 04/08/2012 22:51, Brad Dutton wrote:
> I recently discovered how to read from a file but I've having some trouble
> with it. I made a short example program that goes like this:
>
>
> 1. fob = open('c:/python27/a.txt', 'r')
> 2.
> 3. print fob.read()
> 4. print fob.read()
>
> When it runs it returns this:
>
>
> 1. Hey now brown cow
> 2.
>
> It's like it forgets how to read after the first time. This has left me
> very confused. Could you offer any reason why this might be happening?
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
Further to Peter Otten's answer you make want to take a look at readline
or readlines, or check into file iteration. Depends on what you're
trying to achieve :)
--
Cheers.
Mark Lawrence.
More information about the Tutor
mailing list