[Tutor] File pointers

Andrei Kulakov ak@silmarill.org
Mon, 24 Jun 2002 01:31:19 -0400


On Mon, Jun 24, 2002 at 03:14:34PM +1000, BELSEY, Dylan wrote:
> Hi,
> 	I run the following code:
> 
> >>> x = open("script1.py", "r")
> >>> exec x
> In the script
> >>> exec x
> >>> 
> 
> 	As you can see, the second exec() doesn't produce the same result.
> I have deduced that this occurs because the "file pointer", after the first
> call is now sitting at the EOF of the file and so if you make the call
> again, it just sees the EOF.
> 	My question is whether there is a simple way to reset this pointer
>
Yeah - f.seek(0)

> to the beginning of the file again.  I could of course just close and
> re-open the file again but unfortunately the exec() command is run in a loop
> which is executed every 50 ms so I want to cut down on the number of file
> ops.  Also, I am trying to avoid the execfile() command as I use a GUI to
> dynamically select a file.
> 	If anyone has any ideas, I would be glad to hear them.  No doubt the
> solution is a simple one, but I just can't find it.
> 	Thanks in advance,
> 		Dylan
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org