skifile.py 文件源码

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

项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码
def set_quantity(self, element, name, value, default_unit=None):

        # Import Astropy here to avoid import errors for this module for users without an Astropy installation
        from astropy.units import Unit

        try:

            # If this works, assume it is a Quantity (or Angle)
            unit = value.unit

            # Works for Angles as well (str(angle) gives something that is not 'value + unit'
            to_string = str(value.to(value.unit).value) + " " + str(unit)

        except AttributeError:

            if default_unit is not None:
                to_string = str(value) + " " + str(Unit(default_unit))
            else:
                to_string = str(value)  # dimensionless quantity

        # Set the value in the tree element
        element.set(name, to_string)

# -----------------------------------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号