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
On Fri, 7 May 1999, Jason Spisak wrote:
Zope-o-matic fans: floating point property. :-( Anyone have any ideas?
A question: What happens if you do not convert salary?
REQUEST.set('salary',float(salary))
REQUEST.set('salary',salary) Pavlos
Pavlos, I get a ValueError at line 128 in Converters.py in field2float. I thought this was my problem, assuming that it would do it on it's own, and that's when I started on the "converter in the method" route. What do you think? Pavlos Christoforou wrote:
On Fri, 7 May 1999, Jason Spisak wrote:
Zope-o-matic fans: floating point property. :-( Anyone have any ideas?
A question: What happens if you do not convert salary?
REQUEST.set('salary',float(salary))
REQUEST.set('salary',salary)
Pavlos
-- Jason Spisak webmaster@mtear.com
Pavlos: I just got it. Not all of the records have a value in that field. Converters.py won't take '' (nothing) to start with. If I account for that in my external method it should work. I love Python "if salary" so easy, simple, elegant ;-) Thanks for your brain power! Jason Pavlos Christoforou wrote:
On Fri, 7 May 1999, Jason Spisak wrote:
Zope-o-matic fans: floating point property. :-( Anyone have any ideas?
A question: What happens if you do not convert salary?
REQUEST.set('salary',float(salary))
REQUEST.set('salary',salary)
Pavlos
-- Jason Spisak webmaster@mtear.com
On Fri, 7 May 1999, Jason Spisak wrote:
Pavlos:
I just got it. Not all of the records have a value in that field.
Oh I am glad! You really had me there. I was reading your method over and over and I could not spot anything wrong with it. Happy Zoping Pavlos
participants (2)
-
Jason Spisak -
Pavlos Christoforou