1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: GBK -*-
#¶ÁÈ¡Excel±£´æµÄÅäÖÃÎļþµÄ±ãÀû·â×°À࣬¿ÉÒÔÉèÖúöÂÔµÄÐкÍÁеÄÊýÁ¿
# author: troring
# Date: 2011.9.1
# history:  2011.9.1     Created
 
 
import logging
import traceback
 
class DataFileReader(object):
    _SKIP_LINES = 1
    _SKIP_COLUMNS = 1
    def __init__( self ):
        self.commentline = 0
 
    def _ProcessData( self, datalist):
        pass
 
    def _ProcessLine( self, line):
        new = line.replace( "\n", "\t" )
        e = new.split( "\t" )
        skip = self._SKIP_COLUMNS
        self._ProcessData( e[skip:])
 
    def Open( self, filename ):
        try:
            fp = open( filename )
        except Exception, e:
            print str(e)
            print traceback.print_exc()
            logging.error( str(e) )
            logging.error( traceback.print_exc() )
            return False
 
        skip = self._SKIP_LINES
        first = 1
        for line in fp:
            if 0 == skip:
                if first == 1:
                    self.commentline = line
                    first = 0
                else:
                    self._ProcessLine( line )
            else:
                skip -= 1
                continue
        return True