Hi Jason,

   Here's an external method that I've used to populate a TinyTable
from a comma separated text file. You might at least get some ideas
about how to extract stuff from the file using this....



# ReadFile is an external method that reads data from a file uploaded from
# the users computer and produces a TinyTable based on that data.

import string

def ReadFile(self,
             infile,                         # input file.....
             outTableName='defaultTable',    # name of output table
             outTableTitle='',               # title of output table
             outTableColumns='',             # columns for output table
             REQUEST=None,                   # Pass in REQUEST....
             RESPONSE=None):                 # and response...

    if not hasattr(self, outTableName):
        self.manage_addTinyTable(id=outTableName, title=outTableTitle, 
columns=outTableColumns, REQUEST=REQUEST)

    newTT = getattr(self, outTableName)
    newTT.manage_edit(title = outTableTitle, columns = outTableColumns, 
    data = infile.read()
    data = string.replace(data,'\r','\n')
    data = string.replace(data,'\n\n','\n')
    lines = string.split(data,'\n')
    newLines = []
    for i in range(len(lines)):
        line = string.strip(lines[i])
        if line:
            sl = string.split(line,',')
            sl = map(lambda x:'"%s"' % x, sl)

    data = string.join(newLines, '\n')
    return newTT.manage_editData( data, REQUEST )

def main():
    class foo:

        def manage_addTinyTable(self, *args, **kwargs):

        def manage_edit(self, *args, **kwargs):

        def manage_editData(self, data, REQUEST):
            print "In manage_editDdata"
            print data

    import StringIO

    f = StringIO.StringIO()

    print f.read()

    rf = foo()
    rf.defaultTable = foo()

    ReadFile(rf, f)

if __name__=='__main__':


>>>>> "Jason" == Jason C Leach <[EMAIL PROTECTED]> writes:

    Jason> hi,

    Jason> I pass a zope file object (just plane text) to an external
    Jason> method.  The file consists of a list of lines of text.  I'd
    Jason> like to extract those lines from the file and put 'em in a
    Jason> list. Can anyone help with the extraction method?

    Jason> Thanks, j.

    Jason> ......................  ..... Jason C. Leach ... University
    Jason> College of the Cariboo.  ..

    Jason> _______________________________________________ Zope
    Jason> maillist - [EMAIL PROTECTED]
    Jason> http://lists.zope.org/mailman/listinfo/zope ** No cross
    Jason> posts or HTML encoding!  ** (Related lists -
    Jason> http://lists.zope.org/mailman/listinfo/zope-announce
    Jason> http://lists.zope.org/mailman/listinfo/zope-dev )

Zope maillist  -  [EMAIL PROTECTED]
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-dev )

Reply via email to