Python 保存函数的终端输出
这学期刚开始在大学编程,我似乎对我要做的作业有一些问题 在本节中,我需要能够在保存已更改目录的历史记录的同时更改目录。我将更改的值存储在列表中,但当我打印列表时,我得到的是Python 保存函数的终端输出,python,python-3.x,Python,Python 3.x,这学期刚开始在大学编程,我似乎对我要做的作业有一些问题 在本节中,我需要能够在保存已更改目录的历史记录的同时更改目录。我将更改的值存储在列表中,但当我打印列表时,我得到的是[NONE]值 我不知道如何获取os.chdir的字符串输出并存储 elif command_arguments[0] == 'changedir': if len(command_arguments) >= 2: shell_input = shell_input.split(" ")
[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)
os.chdir()
即使成功也会返回None
。如果要在列表中保存目标目录,可以在更改目录后立即使用changed\u dir=os.getcwd()
另请参见:os.chdir()
即使成功也会返回None
。如果要在列表中保存目标目录,可以在更改目录后立即使用changed\u dir=os.getcwd()
另请参见:注意
changed\u dir=os.chdir
将函数os.chdir
分配给名称changed\u dir
。这意味着changed\u dir
将成为一个更改当前工作目录的函数——这不是您想要的!请注意,changed\u dir=os.chdir
将函数os.chdir
分配给名称changed\u dir
。这意味着changed\u dir
将成为一个更改当前工作目录的函数——这不是您想要的!