util.py 文件源码

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

项目:chandl 作者: gebn 项目源码 文件源码
def make_filename(string):
    """
    Turn a string into something that can be safely used as a file or directory
    name.

    :param string: The string to convert.
    :return: The sanitised string.
    :raises ValueError: If string is None.
    """
    if string is None:
        raise ValueError('String cannot be None')

    safe = [' ', '.', '_', '-', '\'']
    joined = ''.join([c for c in unidecode.unidecode(string)
                      if c.isalnum() or c in safe]).strip()
    if not joined:
        raise ValueError('Filename would be empty')
    return joined
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号