프로그래밍/Python 6

[Python3] ZIP Function

zip() 기본 문법 >>> numbers = [1, 2, 3] >>> letters = ["A", "B", "C"] >>> for pair in zip(numbers, letters): ... print(pair) ... (1, 'A') (2, 'B') (3, 'C') >>> numbers = [1, 2, 3] >>> letters = ["A", "B", "C"] >>> for i in range(3): ... pair = (numbers[i], letters[i]) ... print(pair) ... (1, 'A') (2, 'B') (3, 'C') 병렬 처리 zip() 함수를 활용하면 여러 그룹의 데이터를 루프를 한 번만 돌면서 처리할 수 있는데요. 가변 인자를 받기 때문에 2개 이상의 인자를 넘겨서..

Using Rotating-Logging in Python

Python 에서 Log 를 생성할 때 사용하는 기본 내장형 모듈 Linux 기반에서는 많이 사용 : tail -F xxxx.log 식으로 사용하며 모니터링 용으로도 사용함 아래 코드는 10Mb 단위의 로그 파일을 최대 5개까지만 생성하여 로그 유지 용량 기준으로만 생성되고 삭제되기 때문에 로그량에 따라 최대 갯수를 늘리거나 줄여야함 import logging from logging.handlers import RotatingFileHandler # CREATE LOG - GLOBAL PARAMETER logger = logging.getLogger('xxx') def setting_logging(): # file max size를 10MB로 설정 file_max_bytes = 10 * 1024 * 10..

Zip Extract on Memory (Python)

물리적 경로에 압축 해제 하지 않고 메모리에 Bytes로 해제 할 경우 사용 아래는 압축 해제 후 Json Load 까지 진행 def open_zip_file(file_path : str): logger.info('# Zip File Extract START.') json_data = None with zipfile.ZipFile(file_path, 'r') as json_zip_file: for file_name in json_zip_file.namelist(): if '.json' in file_name.lower(): zip_data = json_zip_file.read(file_name).decode('UTF-8') json_data = json.loads(zip_data) return json_..

FTP Sending From Memory (Python)

압축 상태의 파일을 물리적 경로에 해제하지 않고 메모리에 해제 후 FTP 전송 def Sending_FTP_Server(news_id, xml_string : str, json_zip_file_path): logger.info('# FTP SENDING START.') session = ftplib.FTP() session.connect('10.101.33.xxx', 21) session.login('xxxxx', 'xxxxx') session.encoding = 'UTF-8' with zipfile.ZipFile(json_zip_file_path, 'r') as json_zip_file: for file_name in json_zip_file.namelist(): bytes_io = io.BytesIO..

Python 실행 파일 만들기

https://wikidocs.net/21952 # one-file, clean cache $ pyinstaller -F --clean listener_by_python.py 제작한 Python 파일(.py)을 실행파일(.exe)로. PyInstaller를 이용하면 파이썬과 PyQt5로 제작한 GUI 프로그램을 간단하게 실행파일 (exe)로 만들 수 있습니다. (PyInstaller 홈페이지) 실행파일은 파이썬이 설치되어 있지 않은 pc에서도 프로그램을 실행할 수 있도록 해줍니다. PyInstaller 설치 실행파일 만들기 콘솔창 출력되지 않도록 하기 실행파일 하나만 생성하기 PyInstaller 설치 우선 명령프롬프트에서 아래의 명령어를 통해 PyInstaller 패키지를 설치합니다. -> python..