[Baypiggies] scientific notation: string to int

Keith Dart keith at dartworks.biz
Fri Dec 10 00:51:44 CET 2010


=== On Thu, 12/09, Bryce Verdier wrote: ===
> I feel so sheepish... oh well, I doubt I'll make this mistake again.
===

I could use a new wool sweater, so for penance you can shave
yourself. ;-)

But that is a common error. You can validate the data in a try block in
the parser too, and have it return only valid records.

e.g:

try:
	value = float(value)
except ValueError:
	coninue

Regarding read-only attributes, you can do this:

class client(object):
     def __init__(self, name, size):
         self.name = name
         self._size = float(size)
         self.east_coast = bool(re.search("_E", name))
         self.trial = bool(re.search("TR_", name))
         self.demo = bool(re.search("_Demo", name))
         self.zetta = bool(re.search("zetta|Zetta", name))
    
     @property
     def size(self):
         return self._size

IMHO, it's better to not convert to string there, in case you ever want
the actual float. Printing implicitly converts to a string, anyway.


-- Keith Dart

-- 

-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Keith Dart <keith at dartworks.biz>
   public key: ID: 19017044
   <http://www.dartworks.biz/>
   =====================================================================


More information about the Baypiggies mailing list