首页 > 解决方案 > 如何在 ipython(google colab)上使用变量运行 %cd?

问题描述

I want to access folders shared to me on drive, I have created a shortcut on my drive and I wanna access it from there. The problem I'm facing is I want to change directory using variable. But when I use this code:

for boxNo in range(109):
  boxStr = "/gdrive/My Drive/Box Set {}".format(boxNo)
  %cd -q setStr  # The problem is here
  url = !pwd
  print("I have to use this url: " + url[0])

I get this error:

[Errno 0] No such file or directory: 'setStr'

SIDE-NOTE:
echo or !echo both don't work either as I write echo url[0] it displays url[0] on the output. But inside parenthesis, as in print, print(url[0]), it works. My guess is if I could change directory keeping the variable inside parenthesis it would work but I seem to find no way of doing so.

标签: ipythoncd

解决方案


推荐阅读