示例#1
0
def getKey(k,data=None,fn=None):

    '''
    Retrieve data from an ALI inputfile. 
    
    Returns the line following the line that contains the given key. 
    
    @param k: The unique input key word for which the ALI inputfile is 
              searched.
    @type k: str

    @keyword data: The data, ie a file read by readFile with delimiter set to ''
                   A filename must be given if data is None.
                   
                   (default: None)
    @type data: list[str]
    @keyword fn: The ALI input filename. Only used if data is None.
    
                 (default: None)
    @type fn: str
    
    @return: The line following the line that contains given key
    @rtype: str
    
    ''' 
    
    if data is None:
        data = DataIO.readFile(filename=fn,delimiter=None,replace_spaces=0)
    i = DataIO.findKey(0,data,k)
    return data[i+1].replace('\n','')
示例#2
0
def changeKey(k,v,data=None,fn=None):
    
    '''
    Update an ALI inputfile with new information.
    
    Takes an input key and value. The file is searched for the key, and the 
    value is inserted on the next line. 
    
    The content is then returned. This method does not save the file.

    @param k: The unique input key word for which the ALI inputfile is 
              searched.
    @type k: str
    @param v: The value inserted on the next line after key. Must be a 
              formatted string; no formatting is done here.
    @type v: str

    @keyword data: The data, ie a file read by readFile with delimiter set to ''
                   A filename must be given if data is None.
                   
                   (default: None)
    @type data: list[str]
    @keyword fn: The ALI input filename. Only used if data is None.
    
                 (default: None)
    @type fn: str
    
    @return: The data as read from a file or as adapted from the original 
    @rtype: list[str]
    
    '''
    
    if data is None:
        data = DataIO.readFile(filename=fn,delimiter=None,replace_spaces=0)
        data = [line.replace('\n','') for line in data]
    i = DataIO.findKey(0,data,k)
    data[i+1] = v
    return data