[Zope-dev] Float Conversion

Jason Spisak webmaster@mtear.com
Fri, 07 May 1999 16:07:41 -0400


Zope-o-matic fans:

Just to add to my last mail, I tried to use float(X) (from the DTML
users guide) to convert that string in an external method, and then it
changed errors on me.  Now instead of a NameError I get a ValueError,
which means that it is converting, just not to what is being asked for. 
The catch is that the property is indeed (I checked and recreated) a
floating point property. :-( Anyone have any ideas?

Here's the code

"""
External Methods for MTear
"""
import string

def import_candidate(self,file,REQUEST,RESPONSE,URL2):
    """
    External Method to import Candidate data and build Candidate
objects.
    
    file is a tab delimited file object (obtained from a file upload
form).

    """
    added=0
    failed=[]
    while 1:
        line=file.readline()
        if line=="":
            break
        fields=string.split(line,'\t')
        id=fields[0]
        first_name=fields[1]
        last_name=fields[2]
        salary=fields[18]
        if id=='ID':
            continue # bogus first line
        #try:
        REQUEST.set('id',id)
        REQUEST.set('first_name',first_name)
        REQUEST.set('last_name',last_name)
        REQUEST.set('salary',float(salary))
        method=self.manage_addProduct['Candidate'].add
        method(method,REQUEST=REQUEST,RESPONSE=RESPONSE,
                    DestinationURL=lambda url=URL2: url)
        added=added+1
        #except:
        #    failed.append(title) 
    return """<html>
            <p>Added %d candidates.</p>
            <p>Failed to add: <br>
            %s
            </p>
            </html>""" % (added, string.join(failed,"<br>"))
    



Thanks again.
-- 
Jason Spisak
webmaster@mtear.com