Advice on this code

Steve M sjmaster at gmail.com
Thu Oct 13 01:10:59 CEST 2005


                    output.write(wrkmisc(ifile,2582))
                    output.write(wrkviol(ifile,2774,16))
                    output.write(wrkaccid(ifile,3270,16))
                    output.write(wrkmisc2(ifile,3638))
                    output.write(wrkcov(ifile,3666,6))
                    output.write(wrklp(ifile,4314,7))
                    output.write(wrkai(ifile,4909,6))
                    output.write(wrkmisc3(ifile,5707))


Ummm... yuck?
First of all, this program is very hard to understand to somebody who
hasn't written it. ALthough I've never heard of Quote Vista so maybe
that's the problem.

Anyway, if you want to integrate the first program with the second GUI
program, you should convert the first program into a set of functions
that can be called to do everything the first program does.

So basically, take the first program and put everything that's not
already in a function into one. That is, all the code that is at zero
indentation, starting with creating the oConn connection, should be
moved into functions. You can also write a big-mama function that calls
those functions in such a way that it would have the exact same overall
effect as the original script before you moved the code into functions.
You can call this big-mama function 'main'.

Now you can integrate it with the GUI program by importing the first
module from the GUI program and binding the functions to the
appropriate buttons. For example you could bind main to the Start
button you  described.

Also, in the first file, you can put the following lines at the bottom,
and it will allow you to run the original script directly to achieve
the same result, while still being able to import it into a second
program and re-use just the functions.

if __name__ == '__main__':
    main()




More information about the Python-list mailing list