[Zope] Problem working around string.split issue

complaw@hal-pc.org complaw@hal-pc.org
Mon, 31 Dec 2001 22:16:02 GMT


> The problem is likely due to the fact that myFile.data
> is not a string for large files, so you can't split
> it. It is actually a PData object which segments the
> data into chunks for better memory handling.
> 
> If you use the str() function on the file though, that
> should give you what you want:
> 
> theData = str(myFile)

That was it!!!!  Oh God.  All that pulling of hair... banging of head...
gnashing of teeth...

Thank you.  Thank you.  Thank you.

I never suspected this because it worked just fine for the smaller files.  But
then it would have -- only for the smaller files -- now that one knows that a
PData object is returned from .data, rather than the actual contents of the
file.  I didn't even think to look at the source.  Something should be added to
the Zope Book about this (the Appendix on the File object is very scanty).

Yikes.  All that time...

In any case, Cacey, please accept my sincere thanks.

Best wishes,

Ron


> 
> hth,
> -Casey
> 
> --- complaw@hal-pc.org wrote:
> > I have a python script that works just fine in Zope
> > for SMALL input files
> > (between 1-100 cases).  However, Zope returns an
> > error when the input file gets
> > large (100+ cases, depending on the situation).  In
> > the error message, Zope
> > points to a line where I take the input file and
> > split it to create a list of
> > lines.  Note, the same script (with split) works
> > just fine when I run the script
> > in regular python (i.e., outside of Zope).
> > 
> > To get around this, I would normally just read the
> > file one line at a time,
> > however, we don't have access to the sys module in
> > Zope.  I have loaded the
> > input file into a File Object in Zope, and can
> > access it via...
> > 
> > theData = context.myFile.data
> > 
> > The problem that I have is that when you do a split
> > on theData, Zope returns the
> > split error (IF myFile is large enough).
> > 
> > The question I have is, how can I read small chunks
> > of content from the File
> > Object?  This is akin to reading a text file one
> > line at a time.  
> > 
> > Any hints?
> > 
> > Ron
> > 
> > 
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://lists.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists - 
> > 
> > http://lists.zope.org/mailman/listinfo/zope-announce
> >  http://lists.zope.org/mailman/listinfo/zope-dev )
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Send your FREE holiday greetings online!
> http://greetings.yahoo.com
>