本文整理汇总了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','')
示例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