개발자라면 꼭 알아야 할 Base64 인코딩/디코딩 원리와 실습
·
Development/Backend
개발을 하다 보면 알 수 없는 영문 대소문자와 숫자가 섞여 있고, 끝이 = 또는 ==로 끝나는 긴 문자열을 마주칠 때가 있습니다. 바로 Base64 인코딩된 데이터입니다. 오늘은 이 Base64가 도대체 무엇인지, 왜 굳이 데이터 크기가 늘어나는 것을 감수하고 사용하는지, 그리고 파이썬(Python)으로 이를 어떻게 다루는지에 대해 정리해 보려고 합니다.1. Base64란 무엇인가?Base64는 이진 데이터(Binary Data)를 텍스트(ASCII 문자)로 변경하는 인코딩 방식 중 하나입니다. 컴퓨터 분야에서 '64'라는 숫자는 26을 의미합니다. 즉, 64진법을 사용한다는 뜻인데, 64개의 문자로 모든 데이터를 표현한다는 것이 핵심입니다.사용되는 문자: A-Z (26개), a-z (26개), 0-9 ..
[Python] 디렉토리 파일 목록 받아오기
·
Development/Backend
Python으로 디렉토리 내부에 있는 파일 목록을 받아오는 기능을 개발해 보았다. import os def list_files(directory): file_list = [] for root, dirs, files in os.walk(directory): for file in files: file_path = os.path.join(root, file) file_list.append(file_path) return file_list # Example usage # directory_path = "/path/to/directory" directory_path = "C:\Python34" # windows files = list_files(directory_path) for file in files: pri..
[Python] 피보나치 수열
·
Development/Backend
이번에는 파이썬으로 피보나치 수열을 개발해 보았다. 피보나치 수열에 대한 설명이 필요하다면 링크 참고. def fibonacci_numbers(n): a, b = 0, 1 for _ in range(n): print(a, end=' ') a, b = b, a + b print("Fibonacci Numbers:") n = int(input("Enter the number of terms: ")) fibonacci_numbers(n)
[Python] 간단한 계산기
·
Development/Backend
파이썬 기본 문법에 익숙해지기 위해 이것 저것 개발해보고 있다. 이번에는 간단한 계산기를 개발해보았다. 너무 간단하지만 기본 문법이 익숙해져야 하니.. def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def divide(a, b): return a / b print("Simple Calculator") while True: print("0. Quit") print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division") choice = input("Enter your choice (0-4)..
[Python] 텍스트 파일에서 단어 수 세기
·
Development/Backend
파이썬을 공부하며 이것저것 개발해보고 있다. 다른 언어로 같은 기능을 개발했을 때는 훨씬 복잡했던 것 같은데.. 파이썬으로 작성하니 코드가 매우 간단하다. filename = "data/sample.txt" wordcount = {} with open(filename, 'r') as f: for line in f: words = line.split() for word in words: word = word.lower() # 소문자로 단어를 세고 싶은 경우 if word not in wordcount: wordcount[word] = 1 else: wordcount[word] += 1 for key, value in wordcount.items(): print(key, value) 결과는 아래와 같다. i..
[Python] Oracle DB 쿼리 시 Dictionary 형태로 조회하기
·
Development/Backend
Python에서 oracledb 통해 쿼리 시 응답의 기본적인 형태는 Tuple (1, 'Setting up a home network', 'Technology') 이런 형태를 편하게 다루기 위해서는 index를 사용해야 하므로 관리가 어렵다. id = row[0] title = row[1] category = row[2] 찾아보니 cursor의 rowFactory라는 메소드를 오버라이딩 하면 리턴받는 데이터의 형태를 바꿀 수 있다. def make_dic_factory(cursor): column_names = [d[0] for d in cursor.description] def create_row(*args): return dict(zip(column_names, args)) return create..