[Tutor] slide show won't display the images in right order

Kent Johnson kent37 at tds.net
Wed Oct 12 17:37:43 CEST 2005


Joseph Quigley wrote:
> Hi,
> Here's my directory listing as a list:
> ['ga041001.gif', 'ga041002.gif', 'ga041003.gif', 'ga041004.gif',
> 'ga041005.gif', 'ga041006.gif', 'ga041007.gif', 'ga041008.gif',
> 'ga041009.gif', 'ga041010.gif', 'ga041011.gif', 'ga000619.gif',
> 'ga050101.gif', 'ga050102.gif', 'ga050103.gif', 'ga050104.gif',
> 'ga050105.gif', 'ga050106.gif', 'ga050107.gif', 'ga050108.gif',
> 'ga050109.gif', 'ga050111.gif', 'ga050112.gif', 'ga050113.gif',
> 'ga050801.gif', 'ga050114.gif', 'ga050802.gif', 'ga050115.gif',
> 'ga050803.gif', 'ga050116.gif', 'ga050804.gif', 'ga050117.gif',
> 'ga050805.gif', 'ga050118.gif', 'ga050806.gif', 'ga050119.gif',
> 'ga050807.gif', 'ga050121.gif', 'ga050122.gif', 'ga050123.gif',
> 'ga050124.gif', 'ga050125.gif',  'ga780825.gif', 'ga780826.gif',
> 'ga780827.gif', 'ga780828.gif', 'ga780829.gif', 'ga780830.gif']
> 
> When I use:
> files = os.listdir(<theimagesdirectory>)
> x = 0
> direction = 1
> while True:
>     ShowImg(files[x]) # An image display function
>     x += -1
> 
> it doesn't display the images in the right order! It will skip from
> ga050123.gif and go to ga050120.gif!
> 
> Is there any way to counter this?

os.listdir() doesn't guarantee any particular order for the results. How about sorting the list?
files = os.listdir(...)
files.sort()
...etc

Kent

> Thanks,
>     Joe
> 
> PS> This is a console version of the Tkinter version I want to make
> (where I posted earlier). Console is just way easier! :-)
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 



More information about the Tutor mailing list