utils.py 文件源码

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

项目:wltrace 作者: jhshi 项目源码 文件源码
def calc_padding(fmt, align):
    """Calculate how many padding bytes needed for ``fmt`` to be aligned to
    ``align``.

    Args:
        fmt (str): :mod:`struct` format.
        align (int): alignment (2, 4, 8, etc.)

    Returns:
        str: padding format (e.g., various number of 'x').

    >>> calc_padding('b', 2)
    'x'

    >>> calc_padding('b', 3)
    'xx'
    """
    remain = struct.calcsize(fmt) % align
    if remain == 0:
        return ""
    return 'x' * (align - remain)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号