Advertisement
Guest User

nordri

a guest
Oct 10th, 2008
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. # Script para obtener imgenes aleatorias de un directorio.
  2. # Fede Diaz (aka nordri) fede3birras(at)gmail.com
  3.  
  4. #!/usr/bin/env python
  5.  
  6. import random, os
  7.  
  8. # Esta funcin genera un vector con las imgenes del directorio
  9. def total(path):
  10.   try:
  11.     i = 0
  12.     for a in os.listdir(path):
  13.       i += 1
  14.     return i
  15.   except OSError, e:
  16.     print "Error del sistema de archivos:", e
  17.  
  18. path = "PATH donde se encuentran las imgenes"
  19. t = total(path)
  20. numero = random.randint(1,t)
  21. i = 0
  22.  
  23. # Elegimos una imagen y la abrimos con gqview
  24. for fichero in os.listdir(path):
  25.   fname = os.path.join(path, fichero)
  26.   i += 1
  27.   if i == numero:
  28.     print "Elegido %s de %s" %(i,t)
  29.     os.system('gqview  ' + fname)
  30.     break
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement