본문 바로가기

Programming208

Dockerfile 에서 apt로 Nginx 설치시 locale 선택 문제 Dockerfile 내에서 nginx 설치 시(apt install nginx) locale 선택때문에 진행이 안될 때, 아래 코드를 dockerfile nginx 설치 문 이전에 넣으면 해결된다 ENV TZ=Asia/Seoul RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone 2020. 11. 19.
Jupyter notebook with Dockerfile jupyter notebook을 docker에서 실행하기 Dockerfile # tf2.3.0 docker makefile FROM tensorflow/tensorflow:2.3.0-gpu LABEL maintainer="chan" RUN apt-get update && apt-get install -y --no-install-recommends \ ssh git vim curl && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* COPY requirements.txt /tmp/requirements.txt RUN pip3 install --upgrade pip && \ pip3 install setuptools wheel && \ pip3 install -r /.. 2020. 10. 29.
Class, Object - 클래스, 객체 class, object class는 사전에 정의된 특별한 데이터와 메서드의 집합이다. 클래스에 선언된 모양 그대로 생성된 실체를 object(객체)라고 한다. 객체가 소프트웨어에 실체화될 때(메모리에 할당되어 사용될 때), 이 실체를 instance라고 한다. 객체는 인스턴스를 포함할 수 있으며, 포괄적인 의미를 지닌다. 파이썬에서 가장 간단한 형태의 클래스 class ClassName(object): # sentence 1 # ... # sentence n pass >>> x = ClassName() # 클래스 정의에 따라 인스턴스 생성 >>> x class instantiation - 클래스 인스턴스 생성 클래스 인스턴스 생성은 함수 표기법을 사용하여 초기 상태의 객체를 생성하는 일이다. 인스턴스 .. 2020. 10. 16.
exception - 예외처리 exception 파이썬 코드를 컴파일할 때, 발생할 수 있는 두가지 종류의 오류가 있다 syntax error: 구문오류(parsing error: 구문 분석 오류)와 exception: 예외(실행 중 발견되는 오류로 무조건적으로 치명적인 것은 아니다)다. 구문 오류가 있으면 컴파일이 아예 안 되지만, 예외는 실행 중에야 발견할 수 있으므로 신중하게 처리해야 한다 예외처리 예외가 발생했는데 이를 코드 내에서 처리하지 않닸다면, 파이썬은 예외의 오류 메시지와 함께 traceback: 트레이스백(역추적)을 출력한다. 트레이스백은 처리되지 않은 예외가 발생한 지점에서 호출 스택 맨 위까지 수행된 모든 호출 목록을 포함한다. 파이썬에서는 try-except-finally문으로 예외처리 try: # 예외 발생 .. 2020. 10. 13.
Serialization, pickling - 직렬화 pickle pickle은 python object를 가져와서 문자열표현으로 변환한다 pickling(serialization) : object -> bytes unpickling(deserialization) : bytes -> object >>> import pickle >>> class Rectangle: ... def __init__(self, width, height): ... self.width=width ... self.height = height ... self.area = width * height ... >>> rect = Rectangle(10, 20) >>> type(rect) # pickling >>> a=pickle.dumps(rect) >>> a b'\x80\x03c__main.. 2020. 10. 7.
lambda - 람다 lambda를 쓰면 코드 내에서 함수를 간결하게 동적으로 사용할 수 있다 >>> def area(b, h): ... return 0.5 * b * h ... >>> area(5, 4) 10.0 # lambda >>> area = lambda b, h: 0.5 * b * h >>> area(5, 4) 10.0 defaultdict 키 생성시 매우 유용하다 from collections imort defaultdict # 일반적인 defaultdict 초기화 int_dict = defaultdict(int) str_dict = defaultdict(str) # lambda함수를 활용한 초기화 minus_one_dict = defaultdict(lambda: -1) point_zero_dict = defaul.. 2020. 10. 6.