Re: [Zope] trying to open a file in database but couldn't

2006-02-26 Thread Andreas Jung



--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 )


Re: [Zope] trying to open a file in database but couldn't

2006-02-26 Thread Allen Huang
Hi.. thanks for replying and thanks for the helpI 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

2006-02-26 Thread Andreas Pakulat
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 )


[Zope] trying to open a file in database but couldn't

2006-02-25 Thread Allen Huang
I'm trying to open a file that is in database but I got this error message insteadcoercing to Unicode: need string or buffer, instance foundI don't quite understand why. My code looks like thisdef imageSetup(self, dataID, REQUEST): from StringIO import StringIO # Get the original image and data in memory and open thefile imageData=getattr(self, dataID) imageDataFile=StringIO(str(imageData.data))   tfw = open(imageDataFile, "r")I upload a text file into ZOPE database and  the file consist of six lines of float point numbers that I want to use with REQUEST.setI call this method usingdtml-call
 "imageSetup(textFile, REQUEST)" can anyone help me... please...  did I made a mistake with this code
		Yahoo! Mail
Bring photos to life! New PhotoMail  makes sharing a breeze. 
___
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 )