VirtualFile and readFile: do I need to close it afterwards?


When I read a file using the virtual file system, I usually do it roughly like this:

# name is the name of the file I wand to load..
vfs = VirtualFileSystem.getGlobalPtr()
fn = Filename(name)
self.virtualFile = vfs.getFile(fn)
if not self.virtualFile:
    raise IOError("No such file or directory: '%s'" % name)
self.content = self.virtualFile.readFile(True)

Now I was wondering, do I need to close the opened virtualFile again? (how?) Or is it enough to set the reference to None:

self.virtualFile = None

Any comments?



Clearing the virtualFile member is sufficient to close the file.

Note that with panda3d 1.6.x, you can do read from a virtual file much more easily with the new stdpy code:

from direct.stdpy.file import open
f = open(name, 'rb')
self.content =