Python 코드에 이모티콘을 포함하는 방법

Python 코드에 이모티콘을 포함하는 방법

이모티콘은 아이디어나 감정을 표현하는 데 사용되는 작은 디지털 이미지입니다. 이모티콘을 프로그래밍과 통합하는 것은 재미있을 수 있습니다. 프로그래밍을 즐거운 작업으로 만듭니다. 댓글, 커밋 메시지 또는 코드에서 직접 이모티콘을 사용할 수 있습니다. 이모지를 사용하여 프로덕션 로그 및 문서와 같은 지루한 텍스트를 흥미로운 텍스트로 변환할 수 있습니다. 사람들조차도 생산성을 높이는 이모티콘이 있는 라인을 선택하는 경향이 있습니다.





Python은 다용도로 유명하기 때문에 Python을 사용하여 이모티콘에 대해 많은 작업을 수행할 수 있습니다.





Python을 사용하여 이모티콘을 인쇄하는 것은 어려운 것처럼 보이지만 믿을 수 없을 정도로 간단합니다. 유니코드 문자, CLDR 이름 또는 Python 라이브러리를 사용할 수 있습니다. 이모티콘 이모티콘을 인쇄합니다.





유니코드 문자를 사용하여 이모티콘 인쇄

유니코드는 전 세계 모든 언어의 모든 문자와 기호에 코드를 할당하는 범용 문자 인코딩 표준입니다. 모든 이모티콘에는 고유한 유니코드가 할당되어 있습니다. Python에서 유니코드를 사용할 때 다음을 대체하십시오. '+' ~와 함께 '000' 유니코드에서. 그런 다음 유니 코드 접두사 '' .

예를 들어 U+1F605는 U0001F605로 사용됩니다. 여기, '+' 로 대체됩니다 '000' 그리고 '' 유니코드가 접두사로 붙습니다.

# grinning face
print('U0001F600')
# beaming face with smiling eyes
print('U0001F601')
# grinning face with sweat
print('U0001F605')
# rolling on the floor laughing
print('U0001F923')
# face with tears of joy
print('U0001F602')
# slightly smiling face
print('U0001F642')
# smiling face with halo
print('U0001F607')
# smiling face with heart-eyes
print('U0001F60D')
# zipper-mouth face
print('U0001F910')
# unamused face
print('U0001F612')

위의 코드는 다음과 같은 출력을 제공합니다.




🤣




🤐

CLDR 짧은 이름을 사용하여 이모지 인쇄

CLDR은 이모티콘 문자 및 시퀀스에 대한 짧은 문자 이름과 키워드를 수집합니다. 이 방법은 더 편안하고 사용하기 쉽습니다.

# smiling face with sunglasses
print('N{smiling face with sunglasses}')
# grinning face
print('N{grinning face}')
# loudly crying face
print('N{loudly crying face}')
# rolling on the floor laughing
print('N{rolling on the floor laughing}')
# face with tears of joy
print('N{face with tears of joy}')
# slightly smiling face
print('N{slightly smiling face}')
# smiling face with halo
print('N{smiling face with halo}')
# angry face
print('N{angry face}')
# zipper-mouth face
print('N{zipper-mouth face}')
# unamused face
print('N{unamused face}')

위의 코드는 다음과 같은 출력을 제공합니다.




🤣




🤐

이모지 라이브러리를 사용하여 이모지 인쇄

이 라이브러리를 사용하면 이모티콘을 Python 프로그램과 쉽게 통합할 수 있습니다. 그러나 사용하기 전에 이 라이브러리를 설치해야 합니다. 확실하게하다 시스템에 pip가 설치되어 있습니다. . 명령 프롬프트에서 다음을 실행합니다.

pip install emoji

이것은 설치합니다 이모티콘 파이썬 라이브러리. Python 프로그램에서 이 라이브러리를 사용하려면 라이브러리를 가져와야 합니다.

# Import required libraries
from emoji import emojize
# smiling face with sunglasses
print(emojize(':smiling_face_with_sunglasses:'))
# grinning face
print(emojize(':grinning_face:'))
# loudly crying face
print(emojize(':loudly_crying_face:'))
# rolling on the floor laughing
print(emojize(':rolling_on_the_floor_laughing:'))
# face with tears of joy
print(emojize(':face_with_tears_of_joy:'))
# slightly smiling face
print(emojize(':slightly_smiling_face:'))
# smiling face with halo
print(emojize(':smiling_face_with_halo:'))
# angry face
print(emojize(':angry_face:'))
# zipper-mouth face
print(emojize(':zipper-mouth_face:'))
# unamused face
print(emojize(':unamused_face:'))

위의 코드는 다음과 같은 출력을 제공합니다.




🤣




🤐

관련된: Android에서 새 이모티콘을 얻는 방법

텍스트에서 모든 이모티콘 추출

Python을 사용하여 텍스트에서 모든 이모티콘을 쉽게 추출할 수 있습니다. 정규 표현식을 사용하여 수행할 수 있습니다. 명령 프롬프트에서 다음 명령을 실행하여 정규식 라이브러리를 설치합니다.

pip install regex

re.findall() 메소드는 텍스트에서 모든 이모티콘을 찾는 데 사용됩니다.

# Import required libraries
import regex as re
# Text from which you want to extract emojis
text = 'We want to extract these emojis '
# Using regular expression to find and extract all emojis from the text
emojis = re.findall(r'[^w⁠s,. ]', text)
print(emojis)

다음 출력이 표시됩니다.

['', '', '', '', '']

이모티콘을 텍스트로 변환

Python을 사용하여 이모티콘을 텍스트로 변환할 수 있습니다. demoji 도서관. 데모지 라이브러리를 설치하려면 다음 명령을 실행하십시오.

pip install demoji

이모티콘 라이브러리를 설치한 후에는 이모티콘 목록 자체가 자주 업데이트 및 변경되므로 유니코드 컨소시엄의 이모티콘 코드 저장소에서 데이터를 다운로드해야 합니다. 다음 코드를 Python 파일에 붙여넣고 실행하여 필요한 데이터를 다운로드합니다.

# Importing demoji library
import demoji
demoji.download_codes()

마지막으로 다음 코드를 사용하여 이모티콘을 텍스트로 변환합니다.

전화 화면을 수리하는 저렴한 장소
# Import required libraries
import demoji
# Text from where you want to convert emojis
text = 'Convert the given emojis to text'
emojis = demoji.findall(text)
# Print converted emojis
print(emojis)

산출:

{'': 'unamused face',
'': 'grinning face with smiling eyes,
'': 'angry face',
'': 'smiling face with sunglasses,
}

이모티콘을 의미로 바꾸기

이모티콘을 의미로 바꾸려면 이모티콘 라이브러리를 사용하여 쉽게 할 수 있습니다. 다음 코드를 실행하기 전에 pip를 사용하여 이모티콘 라이브러리를 설치해야 합니다.

# Import required libraries
import emoji
# Text from where you want to replace emojis
text = '''These are some of the most used emojis
1.
2.
3. 🤣'''
replaced_text = emoji.demojize(text, delimiters=('', ''))
# Printing replaced text
print(replaced_text)

위의 코드는 다음과 같은 출력을 제공합니다.

These are some of the most used emojis
1. face_with_tears_of_joy
2. smiling_face_with_heart-eyes
3. rolling_on_the_floor_laughing

Python의 텍스트에서 이모티콘 제거

Python의 정규식을 사용하여 텍스트에서 모든 이모티콘을 제거할 수 있습니다.

# Importing Regular Expression Library
import re
# Text from where you want to remove all emojis
text = '''These are some of the most used emojis
1. Emoji 1
2. Emoji 2
'''
# Printing the text with emojis
print(text)
# Function to remove emoji from text
def removeEmoji(text):
regrex_pattern = re.compile(pattern = '['
u'U0001F600-U0001F64F' # emoticons
u'U0001F300-U0001F5FF' # symbols & pictographs
u'U0001F680-U0001F6FF' # transport & map symbols
u'U0001F1E0-U0001F1FF' # flags (iOS)
']+', flags = re.UNICODE)
return regrex_pattern.sub(r'',text)
# Printing the text without emojis
print(removeEmoji(text))

위의 코드는 다음과 같은 출력을 제공합니다.

These are some of the most used emojis
1. Emoji 1
2. Emoji 2
These are some of the most used emojis
1. Emoji 1
2. Emoji 2

이모티콘으로 프로그래밍을 재미있게 만드세요

이모티콘은 이제 텍스트 커뮤니케이션의 필수적인 부분으로 간주됩니다. Python의 힘을 사용하여 많은 작업을 수행할 수 있습니다. 재미있는 프로그래밍을 위해 댓글, 커밋 메시지 등에 이모티콘을 사용하는 습관을 들이세요.

둘 다 이모티콘 및 이모티콘 현재 다양한 조직에서 광범위하게 사용되고 있습니다. 당신은 할 수 있습니다 나만의 이모티콘 만들기 텍스트를 통해 자신을 표현합니다.

공유하다 공유하다 트위터 이메일 가장 인기 있는 100가지 이모티콘 설명

이모티콘이 너무 많아서 모두가 무엇을 의미하는지 알기 어려울 수 있습니다. 다음은 가장 인기 있는 이모티콘에 대한 설명입니다.

다음 읽기
관련 항목
  • 프로그램 작성
  • 파이썬
  • 이모티콘
저자 소개 유브라지 찬드라(60편 게재)

Yuvraj는 인도 델리 대학교의 컴퓨터 공학 학부생입니다. 그는 풀 스택 웹 개발에 열정적입니다. 그는 글을 쓰지 않을 때 다양한 기술의 깊이를 탐구하고 있습니다.

유브라지 찬드라가 참여한 작품 더보기

뉴스레터 구독

뉴스레터에 가입하여 기술 팁, 리뷰, 무료 전자책 및 독점 거래를 확인하십시오!

구독하려면 여기를 클릭하세요.