passing values to a program

Eric_Dexter at msn.com Eric_Dexter at msn.com
Thu Oct 19 00:52:57 EDT 2006


     I almost have this thing running like I want it to run but I want
the values to come from the program that calls this one.  There are two
things I want to pass File_Name and CutString.  They both need to go to
loadFile routine of Class WordGrid to replace constants.  Thank you for
putting up with my quesitons in advance.


import wx
import wx.grid as gridlib



#---------------------------------------------------------------------------

class WordGrid(gridlib.Grid):
    def __init__(self, parent, log):
        gridlib.Grid.__init__(self, parent, -1)


        self.loadFile()

        self.CreateGrid(len(self.rows), self.widestRow)

        for r, row in enumerate(self.rows):
            for c, col in enumerate(row):
                self.SetCellValue(r, c, col)
            self.SetColSize(c, 10*self.widestCol)

        for c, label in enumerate(self.header):
            self.SetColLabelValue(c, label)

    def loadFile(self):
       #from_file
       infile = open('test.sco', 'r')
       foundHeader = False
       self.rows = []
       for line in infile:
           if ";<sco_header>" in line:
               #removefirst = line.split(' ')
               self.header = line.split()
               #foundHeader = 'true'
               continue     # we don't want to process this line any
further
           else:
               self.rows.append(line.split())

       self.widestRow = max([len(r) for r in self.rows])
       self.widestCol = max([len(c) for c in [r for r in self.rows]])



#---------------------------------------------------------------------------

class TestFrame(wx.Frame):
    def __init__(self, parent, log):
        wx.Frame.__init__(self, parent, -1, "Simple Grid Demo",
size=(640,480))
        grid = WordGrid(self, log)

#---------------------------------------------------------------------------
#def main():

def main(From_File, string):
    import sys
    From_file = argv[1]
    #split_string = argv2[2]
    app = wx.PySimpleApp()
    frame = TestFrame(None, sys.stdout)
    frame.Show(True)
    app.MainLoop()
    pass

if __name__ == '__main__':
    import sys
    main('test.sco', 'sfd')

http://www.dexrow.com




More information about the Python-list mailing list