본문 바로가기

반응형

Python

(62)
[Python] 파이썬 dependency 관리 Node를 사용하게 되면 package.json이 자동(?)으로 생성되어 사용하는 package를 관리할 수 있다. (npm등으로 global로 install한게 아니라면 기록된다.) 하지만 python은 자동으로 되지 않는듯 하여, requirements.txt 파일을 생성하여 package를 관리해주어야 하는듯 하다. 1. 현재 install 된 package 확인하기 pip list 주의점은 현재 프로젝트에서 사용되고 있는것만 나오는게 아니라 그냥 전체적으로 install 된 package의 list가 나오므로 필요 없는 package는 없애주는 작업이 필요하다. 2. 설치된 패키지 목록 나열되어 있는 텍스트 파일 만들기 pip freeze > requirements.txt 3. 패키지 한번에 설치..
[python] REST API 호출 (requests 이용) requests 이용 예시 1. requests install docs.python-requests.org/en/latest/user/install/#install python -m pip install requests 2. get import requests # GET res = requests.get('url') print(str(res.status_code) + " | " + res.text) 3. post import requests import json # POST (JSON) headers = {'Content-Type': 'application/json; chearset=utf-8'} data = {'title': 'dummy title', 'id': 1, 'message': 'hello w..
[Python] 날짜 구하기 (날짜 리스트 만들기) 1. 기본적인 날짜 구하기 import datetime # 오늘 날짜 today = datetime.date.today() # 결과 # 2021-04-07 # 오늘 날짜 시간 now = datetime.datetime.now() # 결과 # 2021-04-07 14:47:19.621988 # 어제날짜 yesterday = today – datetime.timedelta(1) # 결과 # 2021-04-06 # 어제날짜 + 시간 yesterday_at_this_time = now – datetime.timedelta(1) # 결과 # 2021-04-06 14:47:19.621988 2. 날짜 리스트 만들기 import datetime def time() : # 나오게할 날짜 갯수 numdays = 10 #..
[PYTHON] TXT 파일 생성 / 수정 / 읽기 (한글깨짐) 1. 기본 내용적기 # 기본 텍스트 신규 입력 file = open("test.txt", "w") file.write("내용입력") file.close() # 한글깨짐 방지 ENCODING UTF-8 file = open("test.txt", "w", encoding="UTF-8") file.write("내용입력") file.close() # 한글깨짐 방지2 ENCODING UTF-8 # txt는 UTF-8로도 충분한데 csv는 UTF-8로만 하면 읽을땐 다른걸로 읽을 경우 깨짐 현상 발생 file = open("test.csv", "w", encoding="UTF-8-sig") file.write("test,test,test\n") file.write("잘되나,안된다,오된다\n") file.close(..
[Python] 기본 문법 f-string에서 중괄호 출력 방법 중괄호 두번써주면 됨 name ='김초보' f''' {{{name}}} ''' # 결과 {김초보} blockdmask.tistory.com/429 [python] 파이썬 f-string (문자열 포매팅 방법 3) 안녕하세요. BlockDMask 입니다. 오늘은 파이썬 문자열 포매팅 방법 % 서식문자, str.format, f-string 이 세개 중 마지막인 f-string에 대해서 알아보려고 합니다. % 서식문자 [바로가기] str.format [바로가기]. blockdmask.tistory.com pythonstudy.xyz/python/article/509-%EB%82%9C%EC%88%98-random 예제로 배우는 파이썬 프로그래밍 - 난수 (random) 난..
[PYTHON] 파이썬 Flask 사용법 2 (Jinja2 템플릿, 변수, 조건문/반복문) jinja.palletsprojects.com/en/2.11.x/templates/ Template Designer Documentation — Jinja Documentation (2.11.x) This document describes the syntax and semantics of the template engine and will be most useful as reference to those creating Jinja templates. As the template engine is very flexible, the configuration from the application can be slightly different from t jinja.palletsprojects.com hleec..
[PYTHON] .gitignore pycache not working .gitignore에 아무리 __pycache__ __pycache__/ __pycache__/* *.pyc 이렇게 넣어줘도 일을 안했다.. # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] 이렇게 써주면 pycache인 .pyc 파일들을 제외 시킬 수 있다. github.com/martinohanlon/flightlight/issues/1 .gitignore and pycache · Issue #1 · martinohanlon/flightlight Hello, you might remove __pycache__ directory and add a .gitignore file like this: # Byte-compiled / optimize..
[python] 파이썬 format 함수 (문자열 포매팅 방법) blockdmask.tistory.com/429?category=324613 [python] 파이썬 f-string (문자열 포매팅 방법 3) 안녕하세요. BlockDMask 입니다. 오늘은 파이썬 문자열 포매팅 방법 % 서식문자, str.format, f-string 이 세개 중 마지막인 f-string에 대해서 알아보려고 합니다. % 서식문자 [바로가기] str.format [바로가기]. blockdmask.tistory.com blockdmask.tistory.com/428?category=324613 [python] 파이썬 % 서식 기호 (문자열 포매팅 방법 2) 안녕하세요 BlockDMask 입니다. 파이썬 문자열 포매팅 방법들 % 서식기호, format함수, f-string중에서 % 서식 기호..

반응형