hi, That's exactly what I'm hoping to do. But for my method, it does not know what read() is, or read_raw(); I get: Zope Error Zope has encountered an error while publishing this resource. Error Type: AttributeError Error Value: read If I try you method I get: Zope Error Zope has encountered an error while publishing this resource. Error Type: AttributeError Error Value: manage_addTinyTable It would probably bail on the read also if it got that far. Perhaps I am caling it wrong, or not pasing the correct object. I jest pass in a Zope File opject, which hapens to be a few lines of text. Thanks, j. ...................... ..... Jason C. Leach ... University College of the Cariboo. .. On Sun, 29 Oct 2000, Steve Spicklemire wrote:
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....
-steve
----------------------------------------------------------------------
# # 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, REQUEST=REQUEST) 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) newLines.append(string.join(sl,','))
data = string.join(newLines, '\n')
return newTT.manage_editData( data, REQUEST )
def main(): class foo:
def manage_addTinyTable(self, *args, **kwargs): pass
def manage_edit(self, *args, **kwargs): pass
def manage_editData(self, data, REQUEST): print "In manage_editDdata" print data
import StringIO
f = StringIO.StringIO() f.write('a,b,c,d\n') f.write('d,e,f,g\n') f.seek(0)
print f.read() f.seek(0)
rf = foo() rf.defaultTable = foo()
ReadFile(rf, f)
if __name__=='__main__':
main()
"Jason" == Jason C Leach <jleach@mail.ocis.net> 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 - Zope@zope.org 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 )