(
        string,
        use_aliases=False,
        delimiters=(_DEFAULT_DELIMITER, _DEFAULT_DELIMITER),
        variant=None,
        language='en',
        version=None,
        handle_version=None
)
return pattern.sub(replace, string)
Replace emoji names in a string with unicode codes.
        >>> import emoji
        >>> print(emoji.emojize("Python is fun :thumbsup:", use_aliases=True))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun :thumbs_up:"))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun __thumbs_up__", delimiters = ("__", "__")))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun :red_heart:",variant="text_type"))
        Python is fun ❤
        >>> print(emoji.emojize("Python is fun :red_heart:",variant="emoji_type"))
        Python is fun ❤️ #red heart, not black heart

    :param string: String contains emoji names.
    :param use_aliases: (optional) Enable emoji aliases.  See ``emoji.UNICODE_EMOJI_ALIAS``.
    :param delimiters: (optional) Use delimiters other than _DEFAULT_DELIMITER
    :param variant: (optional) Choose variation selector between "base"(None), VS-15 ("text_type") and VS-16 ("emoji_type")
    :param language: Choose language of emoji name: language code 'es', 'de', etc. or 'alias'
        to use English aliases
    :param version: (optional) Max version. If set to an Emoji Version,
        all emoji above this version will be ignored.
    :param handle_version: (optional) Replace the emoji above ``version``
        instead of ignoring it. handle_version can be either a string or a
        callable; If it is a callable, it's passed the unicode emoji and the
        data dict from emoji.EMOJI_DATA and must return a replacement string
        to be used::

            handle_version(u'\\U0001F6EB', {
                'en' : ':airplane_departure:',
                'status' : fully_qualified,
                'E' : 1,
                'alias' : [u':flight_departure:'],
                'de': u':abflug:',
                'es': u':avión_despegando:',
                ...
            })

    :raises ValueError: if ``variant`` is neither None, 'text_type' or 'emoji_type'
Replace emoji names in a string with unicode codes.
        >>> import emoji
        >>> print(emoji.emojize("Python is fun :thumbsup:", use_aliases=True))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun :thumbs_up:"))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun __thumbs_up__", delimiters = ("__", "__")))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun :red_heart:",variant="text_type"))
        Python is fun ❤
        >>> print(emoji.emojize("Python is fun :red_heart:",variant="emoji_type"))
        Python is fun ❤️ #red heart, not black heart
Replace emoji names in a string with unicode codes . >>> import emoji >>> print ( emoji . emojize ( Python is fun : thumbsup : use_aliases = True )) Python is fun 👍 >>> print ( emoji . emojize ( Python is fun : thumbs_up : )) Python is fun 👍 >>> print ( emoji . emojize ( Python is fun __thumbs_up__ delimiters = ( __ __ ))) Python is fun 👍 >>> print ( emoji . emojize ( Python is fun : red_heart : variant = text_type )) Python is fun ❤ >>> print ( emoji . emojize ( Python is fun : red_heart : variant = emoji_type )) Python is fun ❤️ #red heart not black heart
def emojize(
        string,
        use_aliases=False,
        delimiters=(_DEFAULT_DELIMITER, _DEFAULT_DELIMITER),
        variant=None,
        language='en',
        version=None,
        handle_version=None
):
    """Replace emoji names in a string with unicode codes.
        >>> import emoji
        >>> print(emoji.emojize("Python is fun :thumbsup:", use_aliases=True))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun :thumbs_up:"))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun __thumbs_up__", delimiters = ("__", "__")))
        Python is fun 👍
        >>> print(emoji.emojize("Python is fun :red_heart:",variant="text_type"))
        Python is fun ❤
        >>> print(emoji.emojize("Python is fun :red_heart:",variant="emoji_type"))
        Python is fun ❤️ #red heart, not black heart

    :param string: String contains emoji names.
    :param use_aliases: (optional) Enable emoji aliases.  See ``emoji.UNICODE_EMOJI_ALIAS``.
    :param delimiters: (optional) Use delimiters other than _DEFAULT_DELIMITER
    :param variant: (optional) Choose variation selector between "base"(None), VS-15 ("text_type") and VS-16 ("emoji_type")
    :param language: Choose language of emoji name: language code 'es', 'de', etc. or 'alias'
        to use English aliases
    :param version: (optional) Max version. If set to an Emoji Version,
        all emoji above this version will be ignored.
    :param handle_version: (optional) Replace the emoji above ``version``
        instead of ignoring it. handle_version can be either a string or a
        callable; If it is a callable, it's passed the unicode emoji and the
        data dict from emoji.EMOJI_DATA and must return a replacement string
        to be used::

            handle_version(u'\\U0001F6EB', {
                'en' : ':airplane_departure:',
                'status' : fully_qualified,
                'E' : 1,
                'alias' : [u':flight_departure:'],
                'de': u':abflug:',
                'es': u':avión_despegando:',
                ...
            })

    :raises ValueError: if ``variant`` is neither None, 'text_type' or 'emoji_type'

    """

    if use_aliases or language == 'alias':
        if language not in ('en', 'alias'):
            warnings.warn("use_aliases=True is only supported for language='en'. "
                          "It is recommended to use emojize(string, language='alias') instead", stacklevel=2)
        use_aliases = True
        language = 'en'

    EMOJI_UNICODE = unicode_codes.EMOJI_ALIAS_UNICODE_ENGLISH if use_aliases else unicode_codes.EMOJI_UNICODE[language]
    pattern = re.compile(u'(%s[\\w\\-&.’”“()!#*+?–,/]+%s)' % delimiters, flags=re.UNICODE)

    def replace(match):
        mg = match.group(1)[len(delimiters[0]):-len(delimiters[1])]
        emj = EMOJI_UNICODE.get(_DEFAULT_DELIMITER + mg + _DEFAULT_DELIMITER)
        if emj is None:
            return match.group(1)

        if version is not None:
            if emj in unicode_codes.EMOJI_DATA and unicode_codes.EMOJI_DATA[emj]['E'] > version:
                if callable(handle_version):
                    return handle_version(emj, unicode_codes.EMOJI_DATA[emj])
                elif handle_version is not None:
                    return str(handle_version)
                else:
                    return ''

        if variant is None or 'variant' not in unicode_codes.EMOJI_DATA[emj]:
            return emj

        if emj[-1] == u'\uFE0E' or emj[-1] == u'\uFE0F':
            # Remove an existing variant
            emj = emj[0:-1]
        if variant == "text_type":
            return emj + u'\uFE0E'
        elif variant == "emoji_type":
            return emj + u'\uFE0F'
        else:
            raise ValueError("Parameter 'variant' must be either None, 'text_type' or 'emoji_type'")

    return pattern.sub(replace, string)
def emojize ( string , use_aliases = False , delimiters = ( _DEFAULT_DELIMITER , _DEFAULT_DELIMITER ) , variant = None , language = 'en' , version = None , handle_version = None ) : if use_aliases or language == 'alias' : if language not in ( 'en' , 'alias' ) : warnings . warn ( "use_aliases=True is only supported for language='en'. " "It is recommended to use emojize(string, language='alias') instead" , stacklevel = 2 ) use_aliases = True language = 'en' EMOJI_UNICODE = unicode_codes . EMOJI_ALIAS_UNICODE_ENGLISH if use_aliases else unicode_codes . EMOJI_UNICODE [ language ] pattern = re . compile ( u'(%s[\\w\\-&.’”“()!#*+?–,/]+%s)' % delim t rs, flags= r .UNIC O DE ) def replace ( match ) : mg = match . group ( 1 ) [ len ( delimiters [ 0 ] ) : - len ( delimiters [ 1 ] ) ] emj = EMOJI_UNICODE . get ( _DEFAULT_DELIMITER + mg + _DEFAULT_DELIMITER ) if emj is None : return match . group ( 1 ) if version is not None : if emj in unicode_codes . EMOJI_DATA and unicode_codes . EMOJI_DATA [ emj ] [ 'E' ] > version : if callable ( handle_version ) : return handle_version ( emj , unicode_codes . EMOJI_DATA [ emj ] ) elif handle_version is not None : return str ( handle_version ) else : return '' if variant is None or 'variant' not in unicode_codes . EMOJI_DATA [ emj ] : return emj if emj [ - 1 ] == u'\uFE0E' or emj [ - 1 ] == u'\uFE0F' : # Remove an existing variant emj = emj [ 0 : - 1 ] if variant == "text_type" : return emj + u'\uFE0E' elif variant == "emoji_type" : return emj + u'\uFE0F' else : raise ValueError ( "Parameter 'variant' must be either None, 'text_type' or 'emoji_type'" ) return pattern . sub ( replace , string )