当前位置: 首页>>代码示例>>Python>>正文


Python File.close方法代码示例

本文整理汇总了Python中file.File.close方法的典型用法代码示例。如果您正苦于以下问题:Python File.close方法的具体用法?Python File.close怎么用?Python File.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在file.File的用法示例。


在下文中一共展示了File.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_netcdf_compare

# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import close [as 别名]
    def test_netcdf_compare(self):
        # self.T = EasyTest(s, l, refdirectory=self.refdir, output_directory = output_directory)

        nx = 10
        ny = 20
        variables = ["var1", "var2", "var3"]
        f1 = tempfile.mktemp(suffix=".nc")
        f2 = tempfile.mktemp(suffix=".nc")
        f3 = tempfile.mktemp(suffix=".nc")
        f4 = tempfile.mktemp(suffix=".nc")

        F1 = File(f1, "x", "y", mode="w")
        F1.create_dimension("x", nx)
        F1.create_dimension("y", ny)

        F2 = File(f2, "x", "y", mode="w")
        F2.create_dimension("x", nx)
        F2.create_dimension("y", ny)

        F3 = File(f3, "x", "y", mode="w")
        F3.create_dimension("x", nx)
        F3.create_dimension("y", ny)

        F4 = File(f4, "x", "y", mode="w")
        F4.create_dimension("x", nx)
        F4.create_dimension("y", ny)

        cnt = 1
        for k in variables:
            x = np.random.random((ny, nx))
            x = np.ma.array(x, mask=x != x)
            F1.append_variable(k, x)
            F2.append_variable(k, x)  # ... two same files
            y = np.random.random((ny, nx))
            y = np.ma.array(y, mask=y != y)
            F3.append_variable(k, y)  # ... and one different
            if cnt == 1:
                F4.append_variable(k, x)  # one file with different number of variables
            cnt += 1

        F1.close()
        F2.close()
        F3.close()
        F4.close()

        T = self.T
        self.assertTrue(T._compare_netcdf(f1, f2, compare_variables=True, compare_values=False))
        self.assertTrue(T._compare_netcdf(f1, f2, compare_variables=False, compare_values=True))
        self.assertTrue(T._compare_netcdf(f1, f2, compare_variables=True, compare_values=True))

        self.assertTrue(T._compare_netcdf(f1, f3, compare_variables=True, compare_values=False))
        self.assertFalse(T._compare_netcdf(f1, f3, compare_variables=False, compare_values=True))
        self.assertFalse(T._compare_netcdf(f1, f3, compare_variables=True, compare_values=True))

        self.assertFalse(T._compare_netcdf(f1, f4, compare_variables=True, compare_values=False))
开发者ID:pygeo,项目名称:easytest,代码行数:57,代码来源:test_easy.py

示例2: close

# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import close [as 别名]
 def close (self):
     self._wasOpened = False
     File.close(self)
     self._rotatingFileSizeEnforcer.shutdown()
开发者ID:afeset,项目名称:miner2-tools,代码行数:6,代码来源:flex_output_file.py

示例3: __init__

# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import close [as 别名]
class Editor:
    """Handles the Gtk.Textview and interacts a File"""
    def __init__(self, textview):
        self.textview = textview
        self.textbuffer = self.textview.get_buffer()
        self.file_handle = File()
        self.textbuffer.set_modified(False)

    def set_font(self, font):
        pass

    def clean_buffer(self):
        startIter, endIter = self.textbuffer.get_start_iter(),\
                             self.textbuffer.get_end_iter()
        self.textbuffer.delete(startIter, endIter)

    def save_as_file(self, filename):
        self.file_handle.close()
        self.file_handle.open(filename, flag="CREATE")
        self.save()

    def open_file(self, filename, flag="READ"):
        state = self.file_handle.open(filename, flag)
        if state == "INEXISTANT":
            return "INEXISTANT"
        elif state == True:
            self.update_editor()
        else:
            print("Failed to open: {file}".format(file=filename))

    def new_file(self, filename=None):
        self.file_handle.close()
        self.file_handle.open(filename)
        self.clean_buffer()
        self.update_editor()

    def replace_file(self, filename):
        self.file_handle.replace(filename)
        self.save()

    def update_editor(self):
        self.textbuffer.set_text(self.file_handle.read())

    def isFileSaved(self):
        return not self.textbuffer.get_modified()

    def get_text(self):
        """Gets the text inside the TextView and returns it"""
        startIter, endIter = self.textbuffer.get_start_iter(),\
                             self.textbuffer.get_end_iter()
        text = self.textbuffer.get_text(startIter, endIter, True)
        return text

    def _set_text(self, text):
        self.textbuffer.set_text(text)

    def save(self):
        """Get textbuffer data and send it to File.save(text)"""

        #Check if we dont have a opened file handle
        if(self.file_handle.save(self.get_text()) == "SELECT_FILE"):
            #If not file is open select one and retry save
            return 'SELECT_FILE'
        else:
            self.textbuffer.set_modified(False)

    def save_and_close(self):
        """Saves and closes without caring about file existance"""
        if self.isFileSaved():
            self.file_handle.close()
        else:
            self.file_handle.save_and_close(self.get_text())
            self.textbuffer.set_modified(False)

    def exit(self):
        if not self.isFileSaved():
            self.save()
        self.file_handle.close()
开发者ID:someoneigna,项目名称:python-projects,代码行数:80,代码来源:editor.py


注:本文中的file.File.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。