Reading from files in python
Question: I need to find out the maximum and minimum value in a line by reading a file
and should be dividing the maximum value by the minimum value. Am interested
to do this in python.

the contents of the file (file.txt) looks like this..

    
    
    A28102_at,151,263,88,484,118,270,458,872,62,194
    AB000114_at,72,21,20,61,20,85,20,25,20,65
    AB000115_at,281,250,358,118,197,71,168,296,198,113
    

The problem am facing is i should be neglecting the first value, that is upto
the first occurrence of comma and am unable to figure out a method. And also
am interested to store the values in an array and then do the comparision. Is
this approach correct or any better method is sugegsted?


Answer: Python comes with batteries! Use the csv module to parse csv files:

    
    
    #!/usr/bin/env python
    import csv
    csvobj=csv.reader(open('file.txt','r'))
    for datum in csvobj:
        datum=[float(val) for val in datum[1:]] 
        print(datum)
        maximum=max(datum)
        minimum=min(datum)
        print(maximum/minimum)
    
    # [151.0, 263.0, 88.0, 484.0, 118.0, 270.0, 458.0, 872.0, 62.0, 194.0]
    # 14.064516129
    # [72.0, 21.0, 20.0, 61.0, 20.0, 85.0, 20.0, 25.0, 20.0, 65.0]
    # 4.25
    # [281.0, 250.0, 358.0, 118.0, 197.0, 71.0, 168.0, 296.0, 198.0, 113.0]
    # 5.04225352113
    

