Google colaboratory 如何在Google Colab中更改文件名
在GoogleColab中上传一个文件后,代码如下Google colaboratory 如何在Google Colab中更改文件名,google-colaboratory,Google Colaboratory,在GoogleColab中上传一个文件后,代码如下 from google.colab import files uploaded = files.upload() 如何更改它的名称?我想你猜对了,“上载”保存着你的文件名。是的,您可以出于重命名目的访问它,如下所示: import os src = os.listdir()[1] #find out the file name which u want to rename using indexing dst ='image.jpg'
from google.colab import files
uploaded = files.upload()
如何更改它的名称?我想你猜对了,“上载”保存着你的文件名。是的,您可以出于重命名目的访问它,如下所示:
import os
src = os.listdir()[1] #find out the file name which u want to rename using indexing
dst ='image.jpg' #change it to the destination name
os.rename(src, dst) #rename it
os.listdir()[1] #access the renamed file
import os
dst ='image.jpg'
os.rename(list(uploaded.keys())[0], dst)
现在,如果您上载了多个文件,您应该注意选择哪个文件,因为“上载”是一个字典,不能保证以任何方式进行排序。rename file optionI希望尽可能避免装载驱动器。这不是一个快速的代码行。我只需要重命名一个文件。