writing to and reading from file

I haven’t found any info in the manual about writing to or reading from files.
I want to be able to write a simple file like an .ini that keep data such as players names, time played, when the game is played for the first time, etc.
Where can I find info on this?

I’d reccomend using python’s built-in file features.

network-theory.co.uk/docs/py … Files.html

That’s because this is not Panda-specific information. It requires Python functions. Look up tutorials or books on Python, working with external files. Here is an example:

diveintopython.org/file_hand … jects.html

Thank very much for the info.
I am assuming I just have to write these codes along with my other codes. Am I right?

Yes. Because file() and open() work with os-specific paths, you might need a Filename(“bllahblah”).toOsSpecific() here and there to make sure your game works on all platforms.

Also, see this:
panda3d.org/manual/index.php/File_Reading

Thanks a heap.
I didn’t even realize that the manual had a few updates, like Cg Tutorials. When I downloaded 1.5.4, I realized it didn’t contain the manual. Let us know when an update of the manual would be available for download. Thanks

Actually, the manual is constantly being updated, so every offline copy is basically outdated within a couple of hours/days already.
Every x.x.0 release has a downloadable version of the manual, so wait for the upcoming 1.6.0. :slight_smile:

Great!
I’m having some problems with these codes.
I tried:

        # Create a log file
        recordFile = ('rec.txt', 'w')
        recordFile.write('File INI')
        recordFile.close()
        print file('rec.txt').read()

and got this error:
AttributeError: ‘tuple’ object has no attribute ‘write’

Also I used:

from direct.stdpy.file import *

and got this:
ImportError: No module named stdpy.file

recordFile = ('rec.txt', 'w') 

That should probably be:

recordFile = open('rec.txt', 'w') 

or (makes no difference);

recordFile = file('rec.txt', 'w') 

The import error means that the “stdpy” module doesn’t exist, which is because it only works in Panda versions 1.6.0 and later (which isn’t released yet).

What??? Did I do that???
My eyes must be in my pants. I should be whipped.
Sorry for that stupid mistake. Thanks for your help.