파이썬[Python]: base64 - encodebytes 함수

파이썬(Phthon): base64 모듈 - encodebytes 함수(function)


/// 설명

Base64를 사용하여 바이트 객체를 인코딩합니다.(이 객체에는 바이너리 데이터가 포함되어질 수 있습니다.)
인코딩 결과를 보시면 76바이트마다 개행문자가 입력되어 있음을 확인하실 수 있으실 겁니다.

※ 형식
base64.encodebytes(bytes)

reference
https://docs.python.org/3/library/base64.html#module-base64

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from base64 import *
 
test_str = 'Encode the bytes-like object s, \
which can contain arbitrary binary data, and \
return bytes containing the base64-encoded data, \
with newlines (b\'\\n\') inserted after every 76 bytes \
of output, and ensuring that there is a trailing \
newline, as per RFC 2045 (MIME).'
test_bytes = bytes(test_str, 'utf-8')
 
# encoding
test_encode = encodebytes(test_bytes)
print('Original string:', test_str)
# Original string: Encode the bytes-like object s, which can contain arbitrary binary data, and return bytes containing the base64-encoded data, with newlines (b'\n') inserted after every 76 bytes of output, and ensuring that there is a trailing newline, as per RFC 2045 (MIME).
print('Bytes          :', test_bytes)
# Bytes          : b"Encode the bytes-like object s, which can contain arbitrary binary data, and return bytes containing the base64-encoded data, with newlines (b'\\n') inserted after every 76 bytes of output, and ensuring that there is a trailing newline, as per RFC 2045 (MIME)."
print('Base64 encoded :', test_encode)
# Base64 encoded : b'RW5jb2RlIHRoZSBieXRlcy1saWtlIG9iamVjdCBzLCB3aGljaCBjYW4gY29udGFpbiBhcmJpdHJh\ncnkgYmluYXJ5IGRhdGEsIGFuZCByZXR1cm4gYnl0ZXMgY29udGFpbmluZyB0aGUgYmFzZTY0LWVu\nY29kZWQgZGF0YSwgd2l0aCBuZXdsaW5lcyAoYidcbicpIGluc2VydGVkIGFmdGVyIGV2ZXJ5IDc2\nIGJ5dGVzIG9mIG91dHB1dCwgYW5kIGVuc3VyaW5nIHRoYXQgdGhlcmUgaXMgYSB0cmFpbGluZyBu\nZXdsaW5lLCBhcyBwZXIgUkZDIDIwNDUgKE1JTUUpLg==\n'
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수