保存功能的终端输出

时间:2018-10-12 23:36:28

标签: python python-3.x

这个学期刚开始在uni上编程,而我要进行的这项作业似乎有一些问题。

在本节中,我需要能够更改目录,同时保存更改目录的历史记录。我将更改后的值存储在列表中,但是当我打印列表时,我得到的是[NONE]值。

我不确定如何进一步获取os.chdir的字符串输出并进行存储。

elif command_arguments[0] == 'changedir':
    if len(command_arguments) >= 2:
        shell_input = shell_input.split(" ")
        os.chdir(shell_input[1])
        changed_dir = os.chdir
        history_list.insert(0, changed_dir)
        print(history_list)

1 个答案:

答案 0 :(得分:2)

os.chdir()确实返回None,即使成功也是如此。如果要将目标目录保存在列表中,则可以在更改目录后立即使用changed_dir = os.getcwd()

另请参阅:https://www.tutorialspoint.com/python3/os_chdir.htm

相关问题