Re: 3 small queries

Guido.van.Rossum@cwi.nl
Sat, 28 Jan 1995 11:21:29 +0100

> a) is the read() call on a file 'f' buffered? I am wanting to do the
> equivalent of fgetc(f) to get a single character from a file object.
> One way to do this in Python is to do f.read(1). For obvious speed
> reasons I am hoping read() is buffered ...

Yes it is buffered, unless you open the file with '0' as the buffer
size parameter (open(filename, mode, buffersize)).

> b) is there any way to force the python interpreter to delete all
> the objects in memory on an exit?

No. It tries to do this for you but may fail if there are unconnected
but circularly referenced objects. Why would you need this?

> c) can the "object-base" (the set of objects in memory) be saved to
> a file in some easy fashion, and then be read back in later? I have
> a large object-base that gets updated by some commands, and then I
> want to essentially save the state of the interpreter so that I can
> look at it later. Just to complicate things I might want to look at
> it on a different machine (I might mail the state to someone else).

In 1.2 there will be two modules "pickle" and "shelve" which will let
you save selected objects to a disk (and read them back). They use a
portable representation. There will be no way to save the state of the
entire interpreter, though -- you have to pick the objects you want to
save.

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>