CodeSnippets Reading Files

From PyWiki

Jump to: navigation, search

I found this really useful for reading dotScene files, amongst other things like custom model formats, config files, really anything.

rgm = ogre.ResourceGroupManager.getSingletonPtr()
resourceGroup = "General"
xmlFileList = rgm.findResourceNames(resourceGroup, "*.xml")
for xmlFile in xmlFileList:
    if xmlFile == "some_xml_file_to_read.xml":
        xmlData = rgm.openResource(xmlFile, resourceGroup, searchGroupsIfNotFound=False)
        break
 
assert isinstance(xmlData, ogre.DataStream)
while not xmlData.eof():
    line = xmlData.getLine(trimAfter=True)
    print line
Personal tools