[Baypiggies] scientific notation: string to int

Bryce Verdier bryceverdier at gmail.com
Thu Dec 9 23:50:22 CET 2010


On 12/09/2010 02:53 PM, Rami Chowdhury wrote:
> On Thursday 09 December 2010 21:59:57 Bryce Verdier wrote:
>> 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,

> Well, we already know that string works :S Could you put the setting of
> self.size in a try/except block, and print out the string that's causing the
> ValueError?

That is a good idea, I will try that and see what happens.
>> 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)
> I'm by no means an expert but getters and setters don't strike me as
> particularly Pythonic -- perhaps properties are more so?
>
You know, I've looked into that, but I haven't found any good examples 
yet of how to do that. If you know of any I'm all eyes on learning how 
to implement them.
>> 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
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> http://mail.python.org/mailman/listinfo/baypiggies
>
> ----
> Rami Chowdhury
> "Strangers are just friends who haven't had enough gin." -- Howdle's
> Saying
> +44-7581-430-517 / +88-01819-245544 /+1-408-597-7068



More information about the Baypiggies mailing list