當前位置: 首頁>>代碼示例>>Python>>正文


Python FileParser.transfer_line方法代碼示例

本文整理匯總了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)
開發者ID:ChanChiChoi,項目名稱:OpenMDAO-Framework,代碼行數:54,代碼來源:test_filewrap.py

示例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))
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:21,代碼來源:pdcyl_comp.py


注:本文中的openmdao.util.filewrap.FileParser.transfer_line方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。