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

Kent Johnson kent37 at tds.net
Thu Oct 13 17:40:53 CEST 2005


Joseph Quigley wrote:
> Hey, if you are a Garfield fan or you just want to see the source code, 
> you can download the whole kaboodle (it's cross platform) from: 
> http://www.jqsoftware.com/software/Gacor/gacor-096.py

I hope you like some comments...

IMO the use of the Data class as a global options store is pretty ugly. I would make the data be instance variables and either pass around an instance of Data as needed, or put all the users of the data into the class as well so they can reference the parameters as self.f etc.

This code
    if os.path.exists('C:\Documents and Settings'):
        imgDir = "C:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('D:\Documents and Settings'):
        imgDir = "D:\\Documents and Settings\\%s\\.gacor\\" % user
    if os.path.exists('E:\Documents and Settings'):
        imgDir = "E:\\Documents and Settings\\%s\\.gacor\\" % user
etc.
could be
  for drive in 'CDEFGHIJK':
    if os.path.exists('%s:\Documents and Settings' % drive):
        imgDir = "%s:\\Documents and Settings\\%s\\.gacor\\" % (drive, user)

Do you know you are testing all the drives always? You might want use elif or put a continue in the loop above.

You don't have to convert a string to a list to pull out substrings, you can get slices from a string directly. For example
            date = list(files[x])
            Data.year = date[2] + date[3]
            Data.month = date[4] + date[5]
            Data.day = date[6] + date[7]

could be
            date = files[x]
            Data.year = date[2:4]
            Data.month = date[4:6]
            Data.day = date[6:8]
a similar change would clean up getother() a bit.


In this code
    try:
        files.remove('license.txt')
    except ValueError:
        print

why do you print here? Maybe because you don't know about pass? pass is an empty statement for when you need a block but you don't want it to do anything, e.g.

    try:
        files.remove('license.txt')
    except ValueError:
        pass

You can catch multiple exceptions in one except:
    try:
        m_m = raw_input("\n\nType 'h' for help\nMain Menu> ")
    except (KeyboardInterrupt, TypeError):
        sys.exit()

Kent



More information about the Tutor mailing list