(filename, sep=',', timestampformat="%Y-%m-%d %H:%M", maxlines=_sys.maxsize)
return TemporalNetwork(tedges = tedges)
Reads time-stamped links from a file and returns a new instance 
            of the class TemporalNetwork. The file is assumed to have a header 

                source target time 

            where columns can be in arbitrary order and separated by arbitrary characters. 
            Each time-stamped link must occur in a separate line and links are assumed to be
            directed.
             
            The time column can be omitted and in this case all links are assumed to occur 
            in consecutive time stamps (that have a distance of one). Time stamps can be simple 
            integers, or strings to be converted to UNIX time stamps via a custom timestamp format. 
            For this, the python function datetime.strptime will be used. 

            @param sep: the character that separates columns 
            @param filename: path of the file to read from
            @param timestampformat: used to convert string timestamps to UNIX timestamps. This parameter is 
                ignored, if the timestamps are digit types (like a simple int).
            @param maxlines: limit reading of file to certain number of lines, default sys.maxsize
Reads time-stamped links from a file and returns a new instance 
            of the class TemporalNetwork. The file is assumed to have a header
Reads time - stamped links from a file and returns a new instance of the class TemporalNetwork . The file is assumed to have a header
def readFile(filename, sep=',', timestampformat="%Y-%m-%d %H:%M", maxlines=_sys.maxsize):
        """ Reads time-stamped links from a file and returns a new instance 
            of the class TemporalNetwork. The file is assumed to have a header 

                source target time 

            where columns can be in arbitrary order and separated by arbitrary characters. 
            Each time-stamped link must occur in a separate line and links are assumed to be
            directed.
             
            The time column can be omitted and in this case all links are assumed to occur 
            in consecutive time stamps (that have a distance of one). Time stamps can be simple 
            integers, or strings to be converted to UNIX time stamps via a custom timestamp format. 
            For this, the python function datetime.strptime will be used. 

            @param sep: the character that separates columns 
            @param filename: path of the file to read from
            @param timestampformat: used to convert string timestamps to UNIX timestamps. This parameter is 
                ignored, if the timestamps are digit types (like a simple int).
            @param maxlines: limit reading of file to certain number of lines, default sys.maxsize

        """
        assert (filename != ''), 'Empty filename given'
        
        # Read header
        with open(filename, 'r') as f:
            tedges = []
        
            header = f.readline()
            header = header.split(sep)

            # If header columns are included, arbitrary column orders are supported
            time_ix = -1
            source_ix = -1
            mid_ix = -1
            weight_ix = -1
            target_ix = -1
            for i in range(len(header)):
                header[i] = header[i].strip()
                if header[i] == 'node1' or header[i] == 'source':
                    source_ix = i
                elif header[i] == 'node2' or header[i] == 'target':
                    target_ix = i
                elif header[i] == 'time' or header[i] == 'timestamp':
                    time_ix = i

            assert (source_ix >= 0 and target_ix >= 0), "Detected invalid header columns: %s" % header

            if time_ix<0:
                Log.add('No time stamps found in data, assuming consecutive links', Severity.WARNING)
        
            Log.add('Reading time-stamped links ...')

            line = f.readline()
            n = 1 
            while line and n <= maxlines:
                fields = line.rstrip().split(sep)
                try:
                    if time_ix >=0:
                        timestamp = fields[time_ix]
                        # if the timestamp is a number, we use this 
                        if timestamp.isdigit():
                            t = int(timestamp)
                        else:   # if it is a string, we use the timestamp format to convert it to a UNIX timestamp                                
                            x = _dt.datetime.strptime(timestamp, timestampformat)
                            t = int(_t.mktime(x.timetuple()))
                    else:
                        t = n                
                    if t>=0:
                        tedge = (fields[source_ix], fields[target_ix], t)
                        tedges.append(tedge)
                    else:
                        Log.add('Ignoring negative timestamp in line ' + str(n+1) + ': "' + line.strip() + '"', Severity.WARNING)
                except (IndexError, ValueError):
                    Log.add('Ignoring malformed data in line ' + str(n+1) + ': "' +  line.strip() + '"', Severity.WARNING)
                line = f.readline()
                n += 1
        # end of with open()

        return TemporalNetwork(tedges = tedges)
def readFile ( filename , sep = ',' , timestampformat = "%Y-%m-%d %H:%M" , maxlines = _sys . maxsize ) : assert ( filename != '' ) , 'Empty filename given' # Read header with open ( filename , 'r' ) as f : tedges = [ ] header = f . readline ( ) header = header . split ( sep ) # If header columns are included, arbitrary column orders are supported time_ix = - 1 source_ix = - 1 mid_ix = - 1 weight_ix = - 1 target_ix = - 1 for i in range ( len ( header ) ) : header [ i ] = header [ i ] . strip ( ) if header [ i ] == 'node1' or header [ i ] == 'source' : source_ix = i elif header [ i ] == 'node2' or header [ i ] == 'target' : target_ix = i elif header [ i ] == 'time' or header [ i ] == 'timestamp' : time_ix = i assert ( source_ix >= 0 and target_ix >= 0 ) , "Detected invalid header columns: %s" % header if time_ix < 0 : Log . add ( 'No time stamps found in data, assuming consecutive links' , Severity . WARNING ) Log . add ( 'Reading time-stamped links ...' ) line = f . readline ( ) n = 1 while line and n <= maxlines : fields = line . rstrip ( ) . split ( sep ) try : if time_ix >= 0 : timestamp = fields [ time_ix ] # if the timestamp is a number, we use this  if timestamp . isdigit ( ) : t = int ( timestamp ) else : # if it is a string, we use the timestamp format to convert it to a UNIX timestamp                                 x = _dt . datetime . strptime ( timestamp , timestampformat ) t = int ( _t . mktime ( x . timetuple ( ) ) ) else : t = n if t >= 0 : tedge = ( fields [ source_ix ] , fields [ target_ix ] , t ) tedges . append ( tedge ) else : Log . add ( 'Ignoring negative timestamp in line ' + str ( n + 1 ) + ': "' + line . strip ( ) + '"' , Severity . WARNING ) except ( IndexError , ValueError ) : Log . add ( 'Ignoring malformed data in line ' + str ( n + 1 ) + ': "' + line . strip ( ) + '"' , Severity . WARNING ) line = f . readline ( ) n += 1 # end of with open() return TemporalNetwork ( tedges = tedges )