본문 바로가기

반응형

Python

(16)
[Python] pymysql connection option pymysql.connections.Connection() class parameterclass pymysql.connections.Connection(*, user=None, password='', host=None,database=None, unix_socket=None, port=0, charset='', sql_mode=None,read_default_file=None, conv=None, use_unicode=True, client_flag=0,cursorclass=, init_command=None,connect_timeout=10, read_default_group=None, autocommit=False,local_infile=False, max_allowed_packet=16777216,..
[Linux] shell script - python exit code exit code?종료 코드란 명령 또는 스크립트가 실행된 수 수신된 코드값이다. 종료 코드는 명령/스크립트의 결과에 대한 단서(성공/실패/기타 조건)를 보고하는 시스템이다.동의어로, '종료 상태', '반환 코드', '종료 상태 코드'가 있다.누군가 요청하지 않는 한 종료 코드는 스스로 출력하지 않는다.종료 코드는 코드 디버깅에 사용된다.종료 코드는 다양한 시스템 통합에 유용하다.python~shell exit codeshell로 python script를 실행하게 되면 python script 실행 결과에 대한 exit code를 반환해 볼 수 있을 것이다.이때 python은 'Sucess Exit Code'값으로 '0', 'Failure Exit Code'값으로 '1'을 반환한다.또는 사용자 지정 종..
[Python] Jinja template Jinja (template engine)Jinja wikipedia Jinja (template engine) - WikipediaFrom Wikipedia, the free encyclopedia Template engine for the Python programming language associated with the Flask framework Jinja is a web template engine for the Python programming language. It was created by Armin Ronacher and is licensed under a BSD Len.wikipedia.org Jinja는 Python용 웹 템플릿 엔진이다.Jinja는 Flask의 기본 템플릿 엔진이며..
[BQ] Python에서 BigQuery 실행하기 Python Client for Google BigQuery Example Usage 구글 GCS 서비스 계정 json 파일을 사용하여 BigQuery에 쿼리 실행하기 from google.cloud import bigquery CREDS = 'test_service_account.json' client = bigquery.Client.from_service_account_json(json_credentials_path=CREDS) job = client.query('select * from dataset1.mytable') for row in job.result(): print(row) Reference https://stackoverflow.com/questions/45003833/how-to-run..
[Python] datetime format python datetime 공식문서YYYYMMDD 형식으로 파라미터를 입력 받아서 sql 쿼리에 사용할 때 유용하게 사용하는 tip 이다.import datetimetarget_date_str = '20230418'target_date_formatted = f"{target_date_str[:4]}-{target_date_str[4:6]}-{target_date_str[6:8]}"print(target_date_formatted)target_dt_formatted = f"{target_date_formatted} 00:00:00"print(target_dt_formatted)target_date_formatted_utc = ( datetime.datetime.strptime(target_dt_fo..
[Python] sqlalchemy - text sqlalchemy using textpython의 sqlalchemy 모듈을 사용해서 mariadb에 execute 할 때, delete 텍스트문이 실행되지 않는 문제가 발생했다.이 문제의 원인과 해결법을 알아보자.  처음에 실행한 코드는 다음과 같다.import sqlalchemy as sa# connect MariaDBmariadb_user: str = config["datasource"]["user"]mariadb_password: str = config["datasource"]["password"]mariadb_host: str = config["datasource"]["host"]mariadb_port: int = config["datasource"]["port"]mariadb_dbname: ..
[Python] Redis connection Redis 접속 후 리턴값 옵션 설정기본적으로 python에서 redis에서 정보를 get 해올 때, b''로 값이 출력된다.이때 b의 의미와 이걸 제거하고 값만 출력하도록 옵션 설정을 한다. def connect_redis(): redis_host = config['redis']['host'] redis_port = config['redis']['port'] redis_db = config['redis']['db'] rd = redis.Redis(host=redis_host, port=redis_port, db=redis_db, charset="utf-8", decode_responses=True) return rdReferencehttps://zedo.tistory.com/..
[Python] PID 의미 PID란?PID(ProcessID/Process IDentification number)는 운영체제에서 프로세스를 식별하기 위해 프로세스에 부여하는 번호를 의미한다.이때 Python으로 서비스 혹은 데몬을 구동할 때 구동되고 있는 PID값이 필요한 경우가 있다.해당 PID에 대한 메모리/CPU 사용량을 보거나 프로세스를 kill 할 수 있다.PPID란?PPID(Parent Process IDentification Number)는 Parent PID이다.PID, PPID 알아내기multiprocessing 방식으로 구동시 child process의 pid(process id)를 알아내기 위한 코드를 작성한다.# pid값 알아내기 (1)import multiprocessingprocess = multipro..

반응형