storage.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:sardana 作者: sardana-org 项目源码 文件源码
def _addCustomData(self, value, name, **kwargs):
        '''
        The custom data will be added as a comment line in the form::

        #C name : value

        ..note:: non-scalar values (or name/values containing end-of-line) will not be written
        '''
        if self.filename is None:
            self.info(
                'Custom data "%s" will not be stored in SPEC file. Reason: uninitialized file', name)
            return
        if numpy.rank(value) > 0:  # ignore non-scalars
            self.info(
                'Custom data "%s" will not be stored in SPEC file. Reason: value is non-scalar', name)
            return
        v = str(value)
        if '\n' in v or '\n' in name:  # ignore if name or the string representation of the value contains end-of-line
            self.info(
                'Custom data "%s" will not be stored in SPEC file. Reason: unsupported format', name)
            return

        fileWasClosed = self.fd is None or self.fd.closed
        if fileWasClosed:
            try:
                self.fd = open(self.filename, 'a')
            except:
                self.info(
                    'Custom data "%s" will not be stored in SPEC file. Reason: cannot open file', name)
                return
        self.fd.write('#C %s : %s\n' % (name, v))
        self.fd.flush()
        if fileWasClosed:
            self.fd.close()  # leave the file descriptor as found
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号