
Python Interpreter
03 Jan 2019 | Python파이썬은 가장 인간의 언어와 유사한 문법으로 프로그래밍할 수 있고 우리가 지금 당장은 몰라도 되는 컴파일(Compile)이라는 과정도 거치지 않는다. 이는 파이썬은 그 외 프로그래밍 언어에 비해 비교적 배우기 쉽고 편하게 접근할 수 있다는 의미이다.포스팅
모듈과 패키지
<내용>
PIP
PyPI, Python Package Index에 등록된 패키지를 설치하자 PyPI는 파이썬으로 작성된 프로그램을 위한 일종의 저장소이다. 2017년 6월을 기준으로 현재 PyPI에는 111003개의 패지지가 등록된 상태이다.Anaconda
현재 가장 널리 사용되는 파이썬 배포판은 컨티눔(Continuum)사가 제작한 '아나콘다(Anaconda)'이다. 아나콘다는 가장 늦게 발표되었음에도 완성도가 뛰어나서 사실상 표준(de facto standard) 파이썬 배포판이 되었다.
<내용>
<내용>
인터프리터 언어 (Interpreted Language)
런타임중에 프로그램 한줄한줄을 해석하며 실행한다.
<내용>
인터프리터 패턴
컴퓨터 프로그래밍에서 인터프리터 패턴(interpreter pattern)은 한 언어에서 문들을 평가하는 방법을 규정하는 디자인 패턴이다. 기본 개념은 특화된 컴퓨터 언어에서 각 기호(종단 또는 비종단)마다 클래스를 갖는 것이다. 언어 내 한 문의 구문 트리는 컴포지트 패턴의 인스턴스이며 클라이언트의 문을 평가(해석)하기 위해 사용된다.
<내용>
자바를 통한 구현.
// Expression interface used to
// check the interpreter.
interface Expression{
boolean interpreter(String con);
}
// TerminalExpression class implementing
// the above interface. This interpreter
// just check if the data is same as the
// interpreter data.
class TerminalExpression implements Expression{
String data;
public TerminalExpression(String data)
this.data = data;
public boolean interpreter(String con){
if(con.contains(data))
return true;
else
return false;
}
}
// OrExpression class implementing
// the above interface. This interpreter
// just returns the or condition of the
// data is same as the interpreter data.
class OrExpression implements Expression{
Expression expr1;
Expression expr2;
public OrExpression(Expression expr1, Expression expr2){
this.expr1 = expr1;
this.expr2 = expr2;
}
public boolean interpreter(String con){
return expr1.interpreter(con) || expr2.interpreter(con);
}
}
// AndExpression class implementing
// the above interface. This interpreter
// just returns the And condition of the
// data is same as the interpreter data.
class AndExpression implements Expression{
Expression expr1;
Expression expr2;
public AndExpression(Expression expr1, Expression expr2){
this.expr1 = expr1;
this.expr2 = expr2;
}
public boolean interpreter(String con){
return expr1.interpreter(con) && expr2.interpreter(con);
}
}
// Driver class
class InterpreterPattern{
public static void main(String[] args){
Expression person1 = new TerminalExpression("Kushagra");
Expression person2 = new TerminalExpression("Lokesh");
Expression isSingle = new OrExpression(person1, person2);
Expression vikram = new TerminalExpression("Vikram");
Expression committed = new TerminalExpression("Committed");
Expression isCommitted = new AndExpression(vikram, committed);
System.out.println(isSingle.interpreter("Kushagra"));
System.out.println(isSingle.interpreter("Lokesh"));
System.out.println(isSingle.interpreter("Achint"));
System.out.println(isCommitted.interpreter("Committed, Vikram"));
System.out.println(isCommitted.interpreter("Single, Vikram"));
}
}
Output:
true
true
false
true
false
장점
문법을 변경하고 확장하는 것은 쉽습니다. 패턴은 클래스를 사용하여 문법 규칙을 나타 내기 때문에 상속을 사용하여 문법을 변경하거나 확장 할 수 있습니다. 기존 표현식은 점진적으로 수정할 수 있으며 새로운 표현식은 이전 표현식의 변형으로 정의 할 수 있습니다. 문법을 구현하는 것도 쉽습니다. 추상 구문 트리의 노드를 정의하는 클래스도 비슷한 구현을합니다. 이러한 클래스는 작성하기 쉽고 컴파일러 나 파서 생성기를 사용하여 생성을 자동화 할 수 있습니다.단점
복잡한 문법은 유지하기 어렵습니다. 인터프리터 패턴은 문법의 모든 규칙에 대해 최소한 하나의 클래스를 정의합니다. 따라서 많은 규칙을 포함하는 문법은 관리 및 유지가 어려울 수 있습니다.인터프리터 종류
CPython
가장 널리 사용되는 “기본” 인터프리터로, 32비트 및 64비트 버전으로 사용 가능합니다(32비트 권장). 최신 언어 기능, 최대 Python 패키지 호환성, 완전한 디버깅 지원 및 IPython과 상호 interop을 포함합니다. 참고 항목: Python 2 또는 Python 3을 사용해야 하나요?. Visual Studio 2015 이전 버전은 Python 3.6+를 지원하지 않으며 Python 버전 3.6이 지원되지 않음과 같은 오류를 표시할 수 있습니다. 대신 Python 3.5 또는 이전을 사용합니다.IronPython
Python의 .NET 구현으로, 32비트 및 64비트 버전으로 사용 가능하며 C#/F#/Visual Basic interop, .NET API에 대한 액세스, 표준 Python 디버깅(그러나 C++ 혼합 모드 디버깅은 제외) 및 혼합 IronPython/C# 디버깅을 제공합니다. 하지만 IronPython에서는 가상 환경을 지원하지 않습니다.Anaconda
Python에서 제공하는 개방형 데이터 과학 플랫폼으로, 최신 버전의 CPython과 설치하기 어려운 대부분의 패키지를 포함합니다. 달리 결정할 수 없는 경우 권장됩니다.PyPy(중요)
Python의 고성능 추적 JIT 구현으로, 장기적으로 실행되는 프로그램과 성능 문제를 확인했으나 다른 해결 방법을 찾을 수 없는 상황에 적절합니다. Visual Studio에서 작동하지만 고급 디버깅 기능은 제한적으로 지원됩니다.Jython
JVM(Java Virtual Machine)에서 Python 구현. IronPython과 마찬가지로, Jython에서 실행되는 코드는 Java 클래스 및 라이브러리와 상호 작용할 수 있지만 CPython용으로 작성된 많은 라이브러리는 사용할 수 없습니다. Visual Studio에서 작동하지만 고급 디버깅 기능은 제한적으로 지원됩니다.+추가 설명
PyPy
PyPy는 유연함과 쉬운 실험을 위해 파이썬 프로그래밍 언어 자체로 작성된 파이썬 구현체이다. 이 프로젝트의 목적 중 하나는 최적화된 PyPy의 파이썬 구현이 현재의 C 구현보다 빠르도록 하는 것이다. PyPy 자체는 파이썬 언어의 부분집합인 RPython으로 구현되어 있다. PyPy는 파이썬 코드를 기계어나 다른 저급 언어로 자동 번역하는 저스트 인 타임 컴파일러 기능을 포함하고 있는데, 특이한 점은 JIT 컴파일러 자체가 JIT 컴파일러 생성기로부터 — PyPy RPython 코드를 분석하여 — 자동생성된다는 점이다. 벤치마크 대상에 따라 다르긴 하지만 PyPy 1.4 버전부터 CPython보다 나은 성능을 보인다. 예를 들어, PyPy 1.4는 PyPy 자체를 컴파일 하는 코드가 CPython보다 PyPy에서 더 빠르게 돌아가는 첫 번째 버전이다.가져온곳: URL