For the life of mine I don’t understand how to combine Panda3D’s and Python’s file handling methods!
The matter is complicated by the fact that I am using ConfigParser from the standard library, which it seems is more selective than pickle.
from panda3d.core import getModelPath from ConfigParser import SafeConfigParser import pickle, os, re def load_ini_data(dbname="shipdescs"): confp = SafeConfigParser() inidir = getModelPath().findAllFiles("assets/ini/%s" % dbname)
But why does:
inidir.getFiles() # crashes?!
crash?! inidir is of type Result, and it must have the method getFiles.
Also, why do I have to apply horrendous preparation to the result, like:
os.listdir(str(inidir).strip()) # prints correctly: ["Filename.ini", "Filename2.ini", ...]
? OK, who cares, it works that way. More importantly, ConfigParser won’t read this file:
for inifile in os.listdir(str(inidir).strip()): file = open(str(inidir).strip()+"/"+inifile, "r") confp.read(file)
However, ch’ing into the target folder in OS X and feeding the open command with a filename I know exists in the target folder works:
inifile = "Filename1.ini" file = open(str(inidir).strip()+"/"+inifile, "r") confp.read(file)
Notice that with pickle the same thing works:
dbfile = open(str(getModelPath().findFile("assets/python/dbpkl/%s.pkl" % dbname)), "r") try: dbdata = pickle.load(dbfile) finally: dbfile.close() return dbdata
Anybode knows how to combine the Panda3D and Python methods appropriately? Somebody have a snippet using only Python’s methods?
This stuff is so simple compared to other stuff in my project I don’t get why it just won’t work.