本文整理汇总了Python中module.Module.fromFile方法的典型用法代码示例。如果您正苦于以下问题:Python Module.fromFile方法的具体用法?Python Module.fromFile怎么用?Python Module.fromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类module.Module
的用法示例。
在下文中一共展示了Module.fromFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fromXML
# 需要导入模块: from module import Module [as 别名]
# 或者: from module.Module import fromFile [as 别名]
def fromXML(XMLString) :
ret = Experiment()
expElement = etree.fromstring(XMLString)
# Extract Experiment's properties from XML attributes and sub-elements
ret.name = expElement.get("name").strip()
ret.stopIsEnabled = eval(expElement.get("stopEnabled").strip().title())
sts = expElement.find("scaleToStandard")
if sts is not None:
ret.scaleToStandard = eval(sts.text.strip().title())
else:
ret.scaleToStandard = False
timeElement = expElement.find("time")
ret.timeUnit = eval(timeElement.get("units").strip())
ret.startTime = float(timeElement.get("start").strip()) | ret.timeUnit
ret.timeStep = float(timeElement.get("step").strip()) | ret.timeUnit
ret.stopTime = float(timeElement.get("end").strip()) | ret.timeUnit
for moduleElement in expElement.findall("module"):
if "name" in moduleElement.attrib:
# Look up the module in our distribution's table and parse the base XML.
moduleName = moduleElement.attrib["name"].strip()
module = Module.fromFile(ModulePaths[moduleName])
elif "file" in moduleElement.attrib:
module = Module.fromFile(moduleElement.attrib["file"])
else:
module = Module.fromXML(moduleElement.text)
ret.modules.append(module)
for initialConditionElement in expElement.findall("initialCondition"):
path = initialConditionElement.get("file").strip()
initCondFile = open(path, 'r')
initCond = cPickle.load(initCondFile)
initCondFile.close()
ret.initialConditions.append(initCond)
ret.initialConditionPaths[initCond] = path
for loggerElement in expElement.findall("logger"):
path = loggerElement.get("file").strip()
loggerFile = open(path, 'r')
logger = cPickle.load(loggerFile)
loggerFile.close()
ret.loggers.append(logger)
ret.loggerPaths[logger] = path
for diagnosticElement in expElement.findall("diagnostic"):
path = diagnosticElement.get("file").strip()
diagnosticFile = open(path, 'r')
diag = cPickle.load(diagnosticFile)
diagnosticFile.close()
ret.diagnostics.append(diag)
ret.diagnosticPaths[diag] = path
particlesElement = expElement.find("particle")
if particlesElement is not None:
ret.particlesPath = particlesElement.get("file").strip()
ret.particles = amuse.support.io.read_set_from_file(particlesPath, "hdf5")
return ret