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

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

How to assign drive links with loop in colab

问题

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

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

  1. from google.colab import drive
  2. drive.mount('/content/drive')
  3. video_1 = "/content/drive/MyDrive/outputs_1"
  4. video_2 = "/content/drive/MyDrive/outputs_2"
  5. video_3 = "/content/drive/MyDrive/outputs_3"
  6. video_4 = "/content/drive/MyDrive/outputs_4"
  7. video_5 = "/content/drive/MyDrive/outputs_5"
  8. video_6 = "/content/drive/MyDrive/outputs_6"
  9. video_7 = "/content/drive/MyDrive/outputs_7"
  10. video_8 = "/content/drive/MyDrive/outputs_8"
  11. video_9 = "/content/drive/MyDrive/outputs_9"
  12. video_10 = "/content/drive/MyDrive/outputs_10"
  13. video_11 = "/content/drive/MyDrive/outputs_11"
  14. 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

  1. from google.colab import drive
  2. drive.mount('/content/drive')
  3. video_1 = "/content/drive/MyDrive/outputs_1"
  4. video_2 = "/content/drive/MyDrive/outputs_2"
  5. video_3 = "/content/drive/MyDrive/outputs_3"
  6. video_4 = "/content/drive/MyDrive/outputs_4"
  7. video_5 = "/content/drive/MyDrive/outputs_5"
  8. video_6 = "/content/drive/MyDrive/outputs_6"
  9. video_7 = "/content/drive/MyDrive/outputs_7"
  10. video_8 = "/content/drive/MyDrive/outputs_8"
  11. video_9 = "/content/drive/MyDrive/outputs_9"
  12. video_10 = "/content/drive/MyDrive/outputs_10"
  13. video_11 = "/content/drive/MyDrive/outputs_11"
  14. video_12 = "/content/drive/MyDrive/outputs_12"

答案1

得分: 0

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

from google.colab import drive

drive.mount('/content/drive')

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

  1. 如果您需要关于列表理解的帮助:
  2. [查看这个!][1]
  3. [1]: https://www.w3schools.com/python/python_lists_comprehension.asp
英文:

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

  1. from google.colab import drive
  2. drive.mount('/content/drive')
  3. 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:

确定