Re: [Zope] trying to open a file in database but couldn't
On 26.02.06 03:52:14, Allen Huang wrote: > I didn't realize that I mis type the code. The code what suppose to be .. >imageDataFile=StringIO(str(dataID.data)) If dataId is a string this won't work. > tfw = open(imageDataFile, "r") > > so, what your saying is that I don't need to open the file that I wanted to > read into and extract the data? But how can that be? You have to forget about files when you're working with ZODB, because this Database doesn't have any file in it. Those are all objects and when you do something like myobj = getattr(self, 'name') you'll get an object. This object might be an instance of the File class and thus behave like a file, but it still is only an object. Your StringIO constructor already get the content of this object, i.e. the text that is stored in it, because you give it via myobj.data. The next thing is, if you already can access the text content via myobj.data you don't need StringIO. > How would you write the external method if you were to read a text file > that you store in ZOPE database and extract the infromation line by line? Suppose dataID contains the id of the object something like this: obj = getattr(self, dataID) for line in str(obj.data).split('\n'): dosth_with(line) That's all. Andreas -- You will gain money by an immoral action. ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] trying to open a file in database but couldn't
Hi.. thanks for replying and thanks for the help I didn't realize that I mis type the code. The code what suppose to be .. imageDataFile=StringIO(str(dataID.data)) tfw = open(imageDataFile, "r") so, what your saying is that I don't need to open the file that I wanted to read into and extract the data? But how can that be? I originally used tried by extracting info from a file on the computer and it works. But I couldn't do the same thing from the web.. I don't get that I did wrong or missing... How would you write the external method if you were to read a text file that you store in ZOPE database and extract the infromation line by line?Andreas Jung <[EMAIL PROTECTED]> wrote: --On 25. Februar 2006 21:55:24 -0800 Allen Huang <[EMAIL PROTECTED]>wrote:> imageDataFile=StringIO(str(imageData.data))> tfw = open(imageDataFile, "r")>Please consult the StringIO documentation. There is no need to open()a StringIO instance...also your code makes little sense to me becausestr() already returns a string which is usually what you need and want.Why do you have the need to put the image data into a StringIO instance.And another point: you should always use cStringIO instead of StringIO(for performance reasons)...consult the Python Library reference for details.-aj Yahoo! Mail Use Photomail to share photos without annoying attachments.___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] trying to open a file in database but couldn't
--On 25. Februar 2006 21:55:24 -0800 Allen Huang <[EMAIL PROTECTED]> wrote: imageDataFile=StringIO(str(imageData.data)) tfw = open(imageDataFile, "r") Please consult the StringIO documentation. There is no need to open() a StringIO instance...also your code makes little sense to me because str() already returns a string which is usually what you need and want. Why do you have the need to put the image data into a StringIO instance. And another point: you should always use cStringIO instead of StringIO (for performance reasons)...consult the Python Library reference for details. -aj pgpFyJJK7yJzV.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )