如何在iPythonwindow中执行windows'move'命令?

How to execute windows 'move' command in iPython window?

我有一个简单的脚本,我需要将文件从当前路径移动到 iPython 笔记本中当前路径的新文件夹。

!move current_file_name NEW_FOLDER

current_file_name 存在并且 NEW_FOLDER 存在,但是,我不断收到错误消息

"The system cannot find the file specified."

当我检查路径的有效性时,它们都是真的。 此命令在 windows 命令提示符下运行良好(没有“!”符号)。

我的完整代码:

import wget
MODEL_ZOO_NAME_PATH = 'http://download.tensorflow.org/models/object_detection/tf2/20200711/ssd_mobilenet_v2_320x320_coco17_tpu-8.tar.gz'
model_zoo_name = wget.download(MODEL_ZOO_NAME_PATH)
if os.path.exists(model_zoo_name):
    print('Modal file name: ',model_zoo_name)
    !move model_zoo_name PRETRAINED_MODEL_PATH
    !cd {PRETRAINED_MODEL_PATH} && tar -zxvf model_zoo_name

输出:

您正在将实际的 model_zoo_name 字符串值传递给 shell,而不是 该变量的内容。使用 $model_zoo_name{model_zoo_name} 获取 内容(第二种形式支持任意 python 表达式)。