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


Python os.remove方法代码示例

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


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

示例1: test_props_write

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_props_write(self):
        announce('test_props_write')
        report = True
        self.env.pwrite(self.env.model_nm + ".props")
        with open(self.env.model_nm + ".props", "r") as f:
            props_written = json.load(f)
        if len(props_written) != len(self.env.props.props):
            report = False
        if report:
            for key in props_written:
                if key not in self.env.props.props:
                    report = False
                    break
                else:
                    if props_written[key]["val"] != self.env.props.props[key].val:
                        report = False
                        break
        f.close()
        os.remove(self.env.model_nm + ".props")
        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:22,代码来源:test_basic.py

示例2: test_list_agents

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_list_agents(self):
        announce('test_list_agents')
        report = True
        orig_out = sys.stdout
        sys.stdout = open("checkfile.txt", "w")
        self.env.list_agents()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checkfile.txt", "r")
        line1 = f.readline()

        for agent in self.env.agents:
            line = f.readline()
            line_list = line.split(" with a goal of ")

            line_list[1] = line_list[1].strip()
            if agent.name != line_list[0] or agent.goal != line_list[1]:
                report = False
                break
        f.close()
        os.remove("checkfile.txt")
        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:24,代码来源:test_basic.py

示例3: test_props_write

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_props_write(self):
        announce('test_props_write')
        report = True
        self.env.pwrite(self.env.model_nm + '.props')
        with open(self.env.model_nm + '.props', 'r') as f:
            props_written = json.load(f)
        if len(props_written) != len(self.env.props.props):
            report = False
        if report:
            for key in props_written:
                if key not in self.env.props.props:
                    report = False
                    break
                elif (props_written[key]["val"] !=
                      self.env.props.props[key].val):
                    report = False
                    break
        f.close()
        os.remove(self.env.model_nm + ".props")
        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:22,代码来源:test_hiv.py

示例4: test_list_agents

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_list_agents(self):
        announce('test_list_agents')
        report = True
        orig_out = sys.stdout
        sys.stdout = open("checkfile.txt", "w")
        self.env.list_agents()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checkfile.txt", "r")
        f.readline()

        for agent in self.env.agents:
            line = f.readline()
            line_list = line.split(" with a goal of ")

            line_list[1] = line_list[1].strip()
            if agent.name != line_list[0] or agent.goal != line_list[1]:
                report = False
                break
        f.close()
        os.remove("checkfile.txt")
        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:24,代码来源:test_hiv.py

示例5: do_iteration

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def do_iteration(self, mutation_fn, aggression):
        """
        This method is called with an output mutation filename and a
        real aggression (see :ref:`aggression`) indicating the amount
        of aggression the fuzzing algorithm should use.  *mutation_fn*
        is unique for every invokation of :meth:`do_iteration`.

        It is an error for this method not to write the mutated
        template to *mutation_fn* before returning a result.  If a
        result is not found, the mutation filename may be written to
        if needed, but it is not required.

        If a notable result is found, it should be returned as a
        :class:`FuzzResult` instance.  This will be stored and reported
        to the ALF central server at the next check-in interval.  A
        return of None indicates a result was not found.

        The filenames of any temporary files or folders created during
        execution can be safely removed using :func:`alf.delete`.  This
        is safer than using :func:`os.remove` or :func:`shutil.rmtree`
        directly.  *mutation_fn* does not need to be deleted, it is
        cleaned up automatically.
        """
        raise NotImplementedError() 
开发者ID:blackberry,项目名称:ALF,代码行数:26,代码来源:__init__.py

示例6: atomic_writer

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def atomic_writer(fpath, mode):
    """Atomic file writer.

    .. versionadded:: 1.12

    Context manager that ensures the file is only written if the write
    succeeds. The data is first written to a temporary file.

    :param fpath: path of file to write to.
    :type fpath: ``unicode``
    :param mode: sames as for :func:`open`
    :type mode: string

    """
    suffix = '.{}.tmp'.format(os.getpid())
    temppath = fpath + suffix
    with open(temppath, mode) as fp:
        try:
            yield fp
            os.rename(temppath, fpath)
        finally:
            try:
                os.remove(temppath)
            except (OSError, IOError):
                pass 
开发者ID:TKkk-iOSer,项目名称:wechat-alfred-workflow,代码行数:27,代码来源:util.py

示例7: exit_maintenance

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def exit_maintenance():
    config = get_config()
    auth = request.authorization
    if auth \
            and auth.username in config.MAINTENANCE_CREDENTIALS \
            and config.MAINTENANCE_CREDENTIALS[auth.username] == auth.password:
        try:
            os.remove(config.MAINTENANCE_FILE)  # remove maintenance file
        except OSError:
            return 'Not in maintenance mode. Ignore command.'
        open(os.path.join(os.getcwd(), 'reload'), "w+").close()  # uwsgi reload
        return 'success'
    else:
        return Response(
            'Could not verify your access level for that URL.\n'
            'You have to login with proper credentials', 401,
            {'WWW-Authenticate': 'Basic realm="Login Required"'}) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:19,代码来源:views_main.py

示例8: download_and_extract

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def download_and_extract(task, data_dir):
    print("Downloading and extracting %s..." % task)
    data_file = "%s.zip" % task
    urllib.request.urlretrieve(TASK2PATH[task], data_file)
    with zipfile.ZipFile(data_file) as zip_ref:
        zip_ref.extractall(data_dir)
    os.remove(data_file)
    print("\tCompleted!") 
开发者ID:Socialbird-AILab,项目名称:BERT-Classification-Tutorial,代码行数:10,代码来源:download_glue.py

示例9: test_remove

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_remove(self):
        report = True
        self.agentpop.add_variety("dummy var")
        dummy_node = node.Node("dummy node")
        dummy_node.ntype = "dummy var"
        self.agentpop.append(dummy_node)
        self.agentpop.remove(dummy_node)
        if dummy_node in self.agentpop.vars['dummy var'][AGENTS]:
            report = False

        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:13,代码来源:test_agent_pop.py

示例10: test_examine_log

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_examine_log(self):
        announce('test_examine_log')
        report = True
        logfile_name = self.env.props.props["model"].val + ".log"
        list_for_reference = deque(maxlen=16)

        with open(logfile_name, 'rt') as log:
            for line in log:
                list_for_reference.append(line)
        orig_out = sys.stdout
        sys.stdout = open("checklog.txt", "w")
        self.env.disp_log()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checklog.txt", "r")
        first_line = f.readline().strip()
        first_line = first_line.split(" ")
        if logfile_name != first_line[-1]:
            report = False
        if report:
            for i, line in enumerate(f):
                if list_for_reference[i] != line:
                    report = False
                    break
        f.close()

        os.remove("checklog.txt")

        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:31,代码来源:test_basic.py

示例11: test_save_session

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_save_session(self):
        announce('test_save_session')
        report = True
        rand_sess_id = random.randint(1, 10)
        try:
            base_dir = self.env.props["base_dir"]
        except:
            base_dir = ""
        self.env.save_session(rand_sess_id)

        path = base_dir + "json/" + self.env.model_nm + str(rand_sess_id) + ".json"
        with open(path, "r") as f:
            json_input = f.readline()
            json_input_dic = json.loads(json_input)
        if json_input_dic["period"] != self.env.period:
            report = False
        if json_input_dic["model_nm"] != self.env.model_nm:
            report = False
        if json_input_dic["preact"] != self.env.preact:
            report = False
        if json_input_dic["postact"] != self.env.postact:
            report = False
        if json_input_dic["props"] != self.env.props.to_json():
            report = False
        #Here is why test_save_session fail before.
        #The env will generate a new prop_arg 2 type proparg when restoring
        #session(check env.from_json function), but 
        # we were using old prop_arg in this test file.
        if json_input_dic["user"] != self.env.user.to_json():
            report = False
        agents = []
        for agent in self.env.agents:
            agents.append(agent.to_json())
        if json_input_dic["agents"] != agents:
            report = False

        f.close()
        os.remove(path)

        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:42,代码来源:test_basic.py

示例12: test_display_props

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_display_props(self):
        announce('test_display_props')
        report = True
        orig_out = sys.stdout
        sys.stdout = open("checkprops.txt", "w")
        self.env.disp_props()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checkprops.txt", "r")
        title = f.readline()
        title_list = title.split(" for ")
        if self.env.model_nm != title_list[1].strip():
            report = False
        dic_for_check = {}
        if report is True:
            for line in f:
                if line != "\n":
                    line_list = line.split(": ")
                    line_list[0] = line_list[0].strip()
                    line_list[1] = line_list[1].strip()
                    dic_for_check[line_list[0]] = line_list[1]

            for key in self.env.props.props:
                if str(self.env.props.props[key]) != dic_for_check[key]:
                    report = False
        f.close()
        os.remove("checkprops.txt")
        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:30,代码来源:test_coop.py

示例13: test_examine_log

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_examine_log(self):
        announce('test_examine_log')
        report = True
        logfile_name = self.env.props.props["log_fname"].val
        list_for_reference = deque(maxlen=16)

        with open(logfile_name, 'rt') as log:
            for line in log:
                list_for_reference.append(line)
        orig_out = sys.stdout
        sys.stdout = open("checklog.txt", "w")
        self.env.disp_log()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checklog.txt", "r")
        first_line = f.readline().strip()
        first_line = first_line.split(" ")
        if logfile_name != first_line[-1]:
            report = False
        if report:
            for i, line in enumerate(f):
                if list_for_reference[i] != line:
                    report = False
                    break
        f.close()

        os.remove("checklog.txt")

        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:31,代码来源:test_coop.py

示例14: test_examine_log

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_examine_log(self):
        announce('test_examine_log')
        report = True
        logfile_name = self.env.props.props["log_fname"].val
        list_for_reference = deque(maxlen=16)

        with open(logfile_name, 'rt') as log:
            for line in log:
                list_for_reference.append(line)
        orig_out = sys.stdout
        sys.stdout = open("checklog.txt", "w")
        self.env.disp_log()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checklog.txt", "r")
        first_line = f.readline().strip()
        first_line = first_line.split(" ")
        if logfile_name != first_line[-1]:
            report = False
        if report:
            for i, line in enumerate(f):
                if list_for_reference[i] != line:
                    report = False
                    break
        f.close()
        os.remove("checklog.txt")
        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:29,代码来源:test_hiv.py

示例15: test_save_session

# 需要导入模块: import os [as 别名]
# 或者: from os import remove [as 别名]
def test_save_session(self):
        announce('test_save_session')
        report = True
        rand_sess_id = random.randint(1, 10)
        try:
            base_dir = self.env.props["base_dir"]
        except:
            base_dir = ""
        self.env.save_session(rand_sess_id)

        path = (base_dir + "json/" + self.env.model_nm +
                str(rand_sess_id) + ".json")
        with open(path, "r") as f:
            json_input = f.readline()
            json_input_dic = json.loads(json_input)
        if json_input_dic["period"] != self.env.period:
            report = False
        if json_input_dic["model_nm"] != self.env.model_nm:
            report = False
        if json_input_dic["preact"] != self.env.preact:
            report = False
        if json_input_dic["postact"] != self.env.postact:
            report = False
        if json_input_dic["props"] != self.env.props.to_json():
            report = False
        if json_input_dic["user"] != self.env.user.to_json():
            report = False
        agents = []
        for agent in self.env.agents:
            agents.append(agent.to_json())

        f.close()
        os.remove(path)

        self.assertEqual(report, True) 
开发者ID:gcallah,项目名称:indras_net,代码行数:37,代码来源:test_hiv.py


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