[Tutor] File pointers

BELSEY, Dylan dylan.belsey@baesystems.com
Mon, 24 Jun 2002 15:14:34 +1000


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
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