本文整理汇总了Python中openmdao.util.filewrap.FileParser.transfer_line方法的典型用法代码示例。如果您正苦于以下问题:Python FileParser.transfer_line方法的具体用法?Python FileParser.transfer_line怎么用?Python FileParser.transfer_line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openmdao.util.filewrap.FileParser
的用法示例。
在下文中一共展示了FileParser.transfer_line方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_output_parse
# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_line [as 别名]
def test_output_parse(self):
data = "Junk\n" + \
"Anchor\n" + \
" A 1, 2 34, Test 1e65\n" + \
" B 4 Stuff\n" + \
"Anchor\n" + \
" C 77 False NaN 333.444\n" + \
" 1,2,3,4,5\n" + \
" Inf 1.#QNAN -1.#IND\n"
outfile = open(self.filename, 'w')
outfile.write(data)
outfile.close()
gen = FileParser()
gen.set_file(self.filename)
gen.set_delimiters(' ')
gen.mark_anchor('Anchor')
val = gen.transfer_var(1, 1)
self.assertEqual(val, 'A')
gen.reset_anchor()
val = gen.transfer_var(3, 2)
self.assertEqual(val, 4)
self.assertEqual(type(val), int)
gen.mark_anchor('Anchor',2)
val = gen.transfer_var(1, 4)
self.assertEqual(isnan(val), True)
val = gen.transfer_var(3, 1)
self.assertEqual(isinf(val), True)
val = gen.transfer_var(3, 2)
self.assertEqual(isnan(val), True)
val = gen.transfer_var(3, 3)
self.assertEqual(isnan(val), True)
val = gen.transfer_line(-1)
self.assertEqual(val, ' B 4 Stuff')
# Now, let's try column delimiters
gen.set_delimiters('columns')
gen.mark_anchor('Anchor',-1)
val = gen.transfer_var(1, 8, 10)
self.assertEqual(val, 'als')
val = gen.transfer_var(1, 17)
self.assertEqual(val, 333.444)
# Test some errors
try:
gen.mark_anchor('C 77', 3.14)
except ValueError, err:
msg = "The value for occurrence must be an integer"
self.assertEqual(str(err), msg)
示例2: load_model
# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_line [as 别名]
def load_model(self, filename):
"""Reads in an existing PDCYL input file and populates the variable
tree with its values."""
infile = FileParser()
infile.set_file(filename)
# Title is a string
self.title = infile.transfer_line(2)
# Print flag becomes a Bool
if infile.transfer_var(4, 1) == 3:
self.icalc = True
else:
self.icalc = False
# Named variables in dictionary
for key, val in self._fields.iteritems():
self.set(val, infile.transfer_var(key, 1))