import sys import re def split_g4_vrml_file(afile): one_string = open(afile).read() split_string = one_string.split('#') file_output_list = {} camera = "" temp = re.compile("---------- (.*)") obj_name = re.compile("(.*): (.*)\..*") for line in split_string: match_it = temp.match(line) if not match_it: continue output = match_it.group(1) if output == "CAMERA": camera = "#" + line continue if camera == "": print "ERROR - Camera", output break # Now get the name of the object match_it = obj_name.match(output) if not match_it: print "ERROR - Name", output break file_output_list[match_it.group(2) + ".wrl"] = \ camera + "#" + line return file_output_list if __name__ == '__main__': out_list = split_g4_vrml_file(sys.argv[1]) for file_name, content in out_list.items(): open(file_name, "w").write(content)