Re: [Zope] Reading and parsing a text file object

2006-07-20 Thread Eric Fernandez

Roberto Benitez wrote:

The following worked for me:
 
with a file object containing the following text:
 
line one of test file

line two of test file
line three of test file
 
I was table to parse lines w/ following code:
 
file=%s % context.textfile

num=1
for line in file.split(\n):
  print LINE %s IS: %s % (num,line)
  num+=1
return printed



result was as follows:
LINE 1 IS: line one of test file  LINE 2 IS: line two of test file  LINE 3 IS: line three of test file  

Thanks a lot, that is very useful. Although I wonder why there is no 
more direct method to do this, this works well.


Cheers,
Eric
___
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] Reading and parsing a text file object

2006-07-20 Thread blists
 Roberto Benitez wrote:
 file=%s % context.textfile

Huh? Isn't that just a weird and probably inefficient way of writing
file=str(context.textfile)?

___
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] Reading and parsing a text file object

2006-07-20 Thread Eric Fernandez

[EMAIL PROTECTED] wrote:

Roberto Benitez wrote:


file=%s % context.textfile
  


Huh? Isn't that just a weird and probably inefficient way of writing
file=str(context.textfile)?

  
Sso I was mistaken when I said \n were removed... I can indeed split by 
'\n' the result of str(context.textfile)


Eric
___
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] Reading and parsing a text file object

2006-07-19 Thread egf05
Hi,

I am new to Zope (but familiar with Python) and have a question.
I have a text file in  a folder and I would like to parse its content, and I
wanted to put the text in a string variable. I understand I can access the
content through file.data or better str(file.data).
However, the string I obtain has no carriage returns anymore, they are replaced
by a space. This is annoying because I cannot split the file line by line.

Is there a trick I do not know? Or is there a better way to parse the content
of a text file object? Any advice would be very appreciated.

Thanks,
Eric
___
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 )