select random img in python using os listdir

Solutions on MaxInterview for select random img in python using os listdir by the best coders in the world

showing results for - "select random img in python using os listdir"
Anna
19 Jan 2019
1import random, os
2path = r"C:\Users\G\Desktop\scientific-programming-2014-master\scientific-programming-2014-master\homework\assignment_3\cifar-10-python\cifar-10-batches-py"
3random_filename = random.choice([
4    x for x in os.listdir(path)
5    if os.path.isfile(os.path.join(path, x))
6])
7print(random_filename)