Answers for "select random img in python using os.listdir"

0

select random img in python using os.listdir

import random, os
path = r"C:\Users\G\Desktop\scientific-programming-2014-master\scientific-programming-2014-master\homework\assignment_3\cifar-10-python\cifar-10-batches-py"
random_filename = random.choice([
    x for x in os.listdir(path)
    if os.path.isfile(os.path.join(path, x))
])
print(random_filename)
Posted by: Guest on May-23-2020

Python Answers by Framework

Browse Popular Code Answers by Language