투케이2K

45. (python/파이썬) encode , decode 사용해 string to byte 변환 수행 실시 본문

Python

45. (python/파이썬) encode , decode 사용해 string to byte 변환 수행 실시

투케이2K 2022. 7. 22. 08:23
반응형

[개발 환경 설정]

개발 툴 : SublimeText (PyScript)

개발 언어 : python

 

[소스 코드]

<!DOCTYPE HTML>
<html lang="ko">
<head>
    <title>WebTest</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">



    <!-- [pyScript 사용 관련 CDN 설정 실시] -->
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>




    <!-- [pyScript 구문 정의 실시] -->
    <py-script>
        print("=====================================")
        print("[main start]")
        print("=====================================")


        # [초기 변수 선언 실시]
        str_Data = "hello"
        print("str_Data : {}".format(str_Data))


        # [encode 사용해 string to byte 변환 수행]
        byte_Data = str_Data.encode("utf-8")
        for k, v in enumerate(byte_Data):
            print("byte_Data : index = {} : byte = {}".format(k, v))
        print("")


        # [decode 사용해 byte to string 변환 수행]
        origin_Data = byte_Data.decode("utf-8")
        print("origin_Data : {}".format(origin_Data))
       
    </py-script>
    
</head>





<!-- [body 콘텐츠 작성] -->
<body>
</body>


</html>
 

[결과 출력]


 
반응형
Comments