qq_28866507
陆壬榎
2017-11-13 03:07

python实现复制指定数量文件到指定目录,出现了一点小问题

  • python
  • 机器学习

import os
import shutil
import random

filenum=100
root="C:/Users/lym/Desktop/20_newsgroups/alt.atheism"
newname="C:/Users/lym/Desktop/train"
name_lst =list(os.path.join(root, name) for name in os.listdir(root))
random_name_lst = list(random.choice(name_lst) for _ in range(0,filenum))
i=0
for _ in random_name_lst:
oldname= random_name_lst[i]
i=i+1
shutil.copy(oldname,newname)

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答