[Zope] Reading File Contents

Cliff Ford Cliff.Ford at ed.ac.uk
Tue Nov 16 06:23:48 EST 2004


That last solution was a bit long-winded. Try this python script (put
theText in the parameter list):

lines = string.split(theText, '\n')
for line in lines:
     (subject, email) = string.split(line, ',')
     print 'Subject=%s, Email=%s' % (subject, email)

return printed

and call it like this:

<dtml-var expr="myList(_.getitem('file_name', 1))">

Cliff

Brokken, Allen P. wrote:
> I am working on a very simple "feedback" type form for my site.  I
> realize this can be achieved with the collector or other intermediately
> complex means, but for this site I need something very light weight and
> simple.  All I need is a table of "Subject","Email address" to be read
> from a file rather than hiding the values in the form.  Basically the
> method that renders the form reads the file and picks up the subjects to
> make a drop down, then when submitted it matches the subject to the
> appropriate email address.  If it's not a valid subject it drops the
> request, and only sends email to the right person.  If this were perl on
> a traditional web server I would have done this in like 60 seconds.  As
> it is I can't figure out how to read in the data from the text file so
> it goes into an array properly.  I was hoping it might be as simple as
> doing
> 
>  
> 
> file_name
> 
> subject1,email1 at host.com
> 
> subject2,email2 at host.com
> 
> subject3,email3 at host2.com
> 
>  
> 
> method
> 
>  
> 
> ... Form header and fields
> 
> <select>
> 
>  
> 
> <dtml-call file_name>
> 
> <dtml-in file_name>
> 
>     <dtml-let keytosplit=sequence-item
> 
>          feedback_name="_.string.split(keytosplit, ',')[0]"
> 
>          email_address="_.string.split(keytosplit, ',')[1]">
> 
>          <option value="<dtml-var feedback_name>"><dtml-var
> feedback_name></select>
> 
>   </dtml-let>
> 
> </dtml-in>
> 
>  
> 
> However it treats file_name as a string and won't let me <dtml-in> over
> that.  Is there a way to easily convert the contents of the file to a
> line by line input for a <dtml-in >statement, or some other quick and
> dirty way to do this?  I've come up with some more complex ways with
> adding a header character to each line to split on, with some form of
> loop through it all, but turning the other file into a set for
> <dtml-let> seems to be the most straight forward way to do it.
> 
>  
> 
> I've come up with half a dozen other ways to handle this that include
> MySQL, or other products, but I really would like it to be as simple as
> possible with as few external dependencies as possible.
> 
>  
> 
> ---
> 
> Allen Brokken
> 
> IAT Services - ISAM
> 
> University of Missouri
> 
> brokkena at missouri.edu
> 
>  
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Zope maillist  -  Zope at 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 )



More information about the Zope mailing list