如何在Colab中使用循环分配驱动器链接

huangapple go评论67阅读模式
英文:

How to assign drive links with loop in colab

问题

我想在一个循环中分配这些链接。但我不知道要使用什么。

我尝试了字典,但我做不到。

from google.colab import drive

drive.mount('/content/drive')

video_1 = "/content/drive/MyDrive/outputs_1"
video_2 = "/content/drive/MyDrive/outputs_2"
video_3 = "/content/drive/MyDrive/outputs_3"
video_4 = "/content/drive/MyDrive/outputs_4"
video_5 = "/content/drive/MyDrive/outputs_5"
video_6 = "/content/drive/MyDrive/outputs_6"
video_7 = "/content/drive/MyDrive/outputs_7"
video_8 = "/content/drive/MyDrive/outputs_8"
video_9 = "/content/drive/MyDrive/outputs_9"
video_10 = "/content/drive/MyDrive/outputs_10"
video_11 = "/content/drive/MyDrive/outputs_11"
video_12 = "/content/drive/MyDrive/outputs_12"
英文:

I want to assign these links in a loop. But I don't know what to use.

I tried dictionary but i couldn't do it

from google.colab import drive

drive.mount('/content/drive')

video_1 = "/content/drive/MyDrive/outputs_1"
video_2 = "/content/drive/MyDrive/outputs_2"
video_3 = "/content/drive/MyDrive/outputs_3"
video_4 = "/content/drive/MyDrive/outputs_4"
video_5 = "/content/drive/MyDrive/outputs_5"
video_6 = "/content/drive/MyDrive/outputs_6"
video_7 = "/content/drive/MyDrive/outputs_7"
video_8 = "/content/drive/MyDrive/outputs_8"
video_9 = "/content/drive/MyDrive/outputs_9"
video_10 = "/content/drive/MyDrive/outputs_10"
video_11 = "/content/drive/MyDrive/outputs_11"
video_12 = "/content/drive/MyDrive/outputs_12"

答案1

得分: 0

如果列表对您有用,您可以这样做:

from google.colab import drive

drive.mount('/content/drive')

video_list = ["/content/drive/MyDrive/outputs_" + str(i) for i in range(1, 13)]


如果您需要关于列表理解的帮助:
[查看这个!][1]


  [1]: https://www.w3schools.com/python/python_lists_comprehension.asp
英文:

If a list works for you, you could do this:

from google.colab import drive

drive.mount('/content/drive')

video_list = ["/content/drive/MyDrive/outputs_" + str(i) for i in range(1, 13)]

If you need help regarding list comprehension:
Check this out!

huangapple
  • 本文由 发表于 2023年3月8日 17:20:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671261.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定