当前位置: 首页>>代码示例>>Python>>正文


Python DataIO.findKey方法代码示例

本文整理汇总了Python中cc.tools.io.DataIO.findKey方法的典型用法代码示例。如果您正苦于以下问题:Python DataIO.findKey方法的具体用法?Python DataIO.findKey怎么用?Python DataIO.findKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cc.tools.io.DataIO的用法示例。


在下文中一共展示了DataIO.findKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getKey

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import findKey [as 别名]
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','')
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:32,代码来源:ALI.py

示例2: changeKey

# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import findKey [as 别名]
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
开发者ID:IvS-KULeuven,项目名称:ComboCode,代码行数:40,代码来源:ALI.py


注:本文中的cc.tools.io.DataIO.findKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。