[Baypiggies] scientific notation: string to int

Bryce Verdier bryceverdier at gmail.com
Thu Dec 9 22:59:57 CET 2010


Hey Keith,

The best I can do for string is the line from my original posting(client 
data, NDA, I'm sure you understand):

b1021384-6633-4756-b3e1-c36d34c1dfd2, clientname_001,Thu Dec  2 00:00:00
UTC 2010,2.96116E+11,0,0, Thu Dec  2 00:00:00 UTC 2010,577078067
20,15228831373,80966857300,


I will say that in the file there are 135 lines in the files. So it's 
not like there is a lot data to deal with. I wonder if I should move 
back to 2.7.

the code is still being worked on, so don't laugh to hard (constructive 
critisims are welcomed though) ;)
#!/usr/bin/python3

import sys
import re
from optparse import OptionParser

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))

     def get_size(self):
         return str(self.size)

     def get_name(self):
         return str(self.name)


def read_file(filename):
     file_data = {}

     with open(filename, 'r') as f:
         for lines in f:
             split_lines = lines.split(',')
             file_data[split_lines[1]] = split_lines[3]

     return file_data

if __name__ == "__main__":

     file1_clients = {}
     file2_clients = {}
     file1_class_clients = []
     file2_class_clients = []

     usage = "%prog [options]"
     parser = OptionParser(usage=usage)
     parser.add_option("-f", "--first", dest="first",
         help="Older file first, builds table from here.")
     parser.add_option("-s", "--second", dest="second",
         help="New file, used for calculating the difference.")

     (options,args) = parser.parse_args()

     if not options.first or not options.second:
         print("The file argument (-f) is nessacary to run this program.\n")
         parser.print_help()
         sys.exit(1)

     file1_clients = read_file(options.first)
     file2_clients = read_file(options.second)

     for x,v in file1_clients.items():
         file1_class_clients.append(client(x,v))

     for x,v in file2_clients.items():
         file2_class_clients.append(client(x,v))

     for x in file1_class_clients:
         print(x.get_name() + ":" + x.get_size())


On 12/09/2010 01:44 PM, Keith Dart wrote:
> === On Thu, 12/09, Bryce Verdier wrote: ===
>> ValueError: could not convert string to float: Commercial Max Space
>> Used
>>
>>
>> This is in python 3.1.2 if that matters.
> ===
>
> Whoa, that's a new one. Not even Google knows about it. Can you supply
> the actual string here?
>
>
>
> -- Keith Dart
>



More information about the Baypiggies mailing list