本文整理汇总了Python中cc.tools.io.DataIO.inputToString方法的典型用法代码示例。如果您正苦于以下问题:Python DataIO.inputToString方法的具体用法?Python DataIO.inputToString怎么用?Python DataIO.inputToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.tools.io.DataIO
的用法示例。
在下文中一共展示了DataIO.inputToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setCommandKey
# 需要导入模块: from cc.tools.io import DataIO [as 别名]
# 或者: from cc.tools.io.DataIO import inputToString [as 别名]
def setCommandKey(self,comm_key,star,key_type,star_key=None,\
alternative=None,make_int=0,exp_not=0):
'''
Try setting a key in the command_list from a star instance.
If the key is unknown, it is left open and will be filled in from the
standard gastronoom inputfile.
@param comm_key: the name of the keyword in the command list
@type comm_key: string
@param star: The parameter set
@type star: Star()
@param key_type: the type of the keyword, either 'DUST' or 'GAS'
@type key_type: string
@keyword star_key: the name of the keyword in the star instance
(minus '_%s'%key_type, which is added as well in a
second attempt if the first without the addition is
not found), if None, it is equal to comm_key
(default: None)
@type star_key: string
@keyword alternative: a default value passed from the standard
inputfile that is used if the keyword or the
keyword + '_%s'%key_type is not found in Star()
(default: None)
@type alternative: string
@keyword make_int: make an integer before converting to string for this
keyword.
(default: 0)
@type make_int: boolean
@keyword exp_not: Convert to exponential notation in a string
(default: 0)
@type exp_not: bool
@return: True if successful, otherwise False.
@rtype: bool
'''
if star_key is None: star_key = comm_key
try:
self.command_list[comm_key] = \
DataIO.inputToString(star[star_key],make_int,exp_not)
return True
except KeyError:
try:
self.command_list[comm_key] = \
DataIO.inputToString(star[star_key+ '_%s'%key_type],\
make_int,exp_not)
return True
except KeyError:
if alternative <> None:
self.command_list[comm_key] = \
DataIO.inputToString(alternative,make_int,exp_not)
return True
else:
return False