ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Python/Reference/소개
    코딩/Python 2024. 3. 15. 14:35
    728x90

    파이썬을 사용하면서 파이썬 매뉴얼을 참고해야 할 경우가 있다. 이럴 경우 매뉴얼의 구성과 용어에 대해 알고 접근하는 것이 도움이 된다.

    그래서 매뉴얼을 설명하는 챕터 1과 2를 번역해 올린다.

    원문은 아래 링크 참조

    1. Introduction

    This reference manual describes the Python programming language. It is not intended as a tutorial.

    While I am trying to be as precise as possible, I chose to use English rather than formal specifications for everything except syntax and lexical analysis. This should make the document more understandable to the average reader, but will leave room for ambiguities. Consequently, if you were coming from Mars and tried to re-implement Python from this document alone, you might have to guess things and in fact you would probably end up implementing quite a different language. On the other hand, if you are using Python and wonder what the precise rules about a particular area of the language are, you should definitely be able to find them here. If you would like to see a more formal definition of the language, maybe you could volunteer your time — or invent a cloning machine :-).

    It is dangerous to add too many implementation details to a language reference document — the implementation may change, and other implementations of the same language may work differently. On the other hand, CPython is the one Python implementation in widespread use (although alternate implementations continue to gain support), and its particular quirks are sometimes worth being mentioned, especially where the implementation imposes additional limitations. Therefore, you’ll find short “implementation notes” sprinkled throughout the text.

    Every Python implementation comes with a number of built-in and standard modules. These are documented in The Python Standard Library. A few built-in modules are mentioned when they interact in a significant way with the language definition.

     

    이 참조 매뉴얼은 Python 프로그래밍 언어를 설명한다. 튜토리얼용으로 제작된 것이 아니다.

    최대한 정확하게 설명하려고 노력하면서 구문 및 어휘 분석을 제외한 모든 항목에 대해 공식적인 사양보다는 영어를 사용하기로 결정했다. 이렇게 하면 일반 독자가 문서를 더 쉽게 이해할 수 있지만 모호함의 여지가 남는다. 결과적으로, 화성에서 와서 이 문서만으로 Python을 다시 구현하려고 한다면 상황을 추측해야 할 수도 있고 실제로는 상당히 다른 언어를 구현하게 될 수도 있다. 반면에, Python을 사용하고 있고 언어의 특정 영역에 대한 정확한 규칙이 무엇인지 궁금하다면 여기에서 확실히 찾을 수 있을 것이다. 언어의 좀 더 공식적인 정의를 보고 싶다면 시간을 내어 자원 봉사를 하거나 복제 기계를 만들 수도 있다 :-).

    언어 참조 문서에 구현 세부 사항을 너무 많이 추가하는 것은 위험하다. 구현이 변경될 수 있으며 동일한 언어의 다른 구현이 다르게 작동할 수 있다. 반면에, CPython은 널리 사용되는 Python 구현 중 하나이며(대체 구현이 계속해서 지원을 받고 있음에도 불구하고), 특히 구현에 추가 제한이 있는 경우 특별한 단점은 언급할 가치가 있다. 따라서 텍스트 전체에 짧은 "구현 참고 사항"이 흩어져 있는 것을 볼 수 있다.

    모든 Python 구현에는 여러 내장 및 표준 모듈이 함께 제공된다. 이는 Python 표준 라이브러리에 문서화되어 있다. 언어 정의와 중요한 방식으로 상호 작용할 때 몇 가지 내장 모듈이 언급된다.

    728x90

    1.1 Alternate Implementations

    Though there is one Python implementation which is by far the most popular, there are some alternate implementations which are of particular interest to different audiences.

    Known implementations include:

     

    지금까지 가장 인기 있는 Python 구현이 하나 있지만, 다양한 대상이 특히 관심을 갖는 몇 가지 대체 구현이 있다.

    알려진 구현은 다음과 같다.

     

    CPython

    This is the original and most-maintained implementation of Python, written in C. New language features generally appear here first.

    이것은 C로 작성된 독창적이고 가장 많이 유지되는 Python 구현이다. 새로운 언어 기능은 일반적으로 여기에 먼저 나타난다.

     

    Jython

    Python implemented in Java. This implementation can be used as a scripting language for Java applications, or can be used to create applications using the Java class libraries. It is also often used to create tests for Java libraries. More information can be found at the Jython website.

    Java로 구현된 Python. 이 구현은 Java 애플리케이션용 스크립팅 언어로 사용되거나 Java 클래스 라이브러리를 사용하여 애플리케이션을 생성하는 데 사용될 수 있다. 또한 Java 라이브러리에 대한 테스트를 만드는 데에도 자주 사용된다. 자세한 내용은 Jython 웹사이트에서 확인할 수 있다.

     

    Python for .NET

    This implementation actually uses the CPython implementation, but is a managed .NET application and makes .NET libraries available. It was created by Brian Lloyd. For more information, see the Python for .NET home page.

    이 구현은 실제로 CPython 구현을 사용하지만 관리되는 .NET 애플리케이션이며 .NET 라이브러리를 사용할 수 있게 만든다. 브라이언 로이드(Brian Lloyd)가 만들었다. 자세한 내용은 .NET용 Python 홈 페이지를 참조한다.

     

    IronPython

    An alternate Python for .NET. Unlike Python.NET, this is a complete Python implementation that generates IL, and compiles Python code directly to .NET assemblies. It was created by Jim Hugunin, the original creator of Jython. For more information, see the IronPython website.

    .NET용 대체 Python이다. Python.NET과 달리 이는 IL을 생성하고 Python 코드를 .NET 어셈블리로 직접 컴파일하는 완전한 Python 구현이다. Jython의 최초 창시자인 Jim Hugunin이 만들었다. 자세한 내용은 IronPython 웹사이트를 참조한다.

     

    PyPy

    An implementation of Python written completely in Python. It supports several advanced features not found in other implementations like stackless support and a Just in Time compiler. One of the goals of the project is to encourage experimentation with the language itself by making it easier to modify the interpreter (since it is written in Python). Additional information is available on the PyPy project’s home page.

    완전히 Python으로 작성된 Python 구현이다. 스택리스 지원 및 Just in Time 컴파일러와 같은 다른 구현에서는 찾을 수 없는 여러 가지 고급 기능을 지원한다. 프로젝트의 목표 중 하나는 인터프리터를 더 쉽게 수정할 수 있도록 하여(파이썬으로 작성되었기 때문에) 언어 자체에 대한 실험을 장려하는 것이다. 추가 정보는 PyPy 프로젝트 홈 페이지에서 확인할 수 있다.

     

    Each of these implementations varies in some way from the language as documented in this manual, or introduces specific information beyond what’s covered in the standard Python documentation. Please refer to the implementation-specific documentation to determine what else you need to know about the specific implementation you’re using.

    이러한 각 구현은 이 매뉴얼에 문서화된 언어와 어느 정도 다르거나 표준 Python 문서에서 다루는 것 이상의 특정 정보를 소개한다. 사용 중인 특정 구현에 대해 알아야 할 추가 사항을 확인하려면 구현별 설명서를 참조한다.

    1.2. Notation

    The descriptions of lexical analysis and syntax use a modified Backus–Naur form (BNF) grammar notation. This uses the following style of definition:

    어휘 분석 및 구문에 대한 설명은 수정된 BNF(Backus-Naur form) 문법 표기법을 사용한다. 이는 다음과 같은 정의 스타일을 사용한다.

    name      ::=  lc_letter (lc_letter | "_")*
    lc_letter ::=  "a"..."z"

     

    The first line says that a name is an lc_letter followed by a sequence of zero or more lc_letters and underscores. An lc_letter in turn is any of the single characters 'a' through 'z'. (This rule is actually adhered to for the names defined in lexical and grammar rules in this document.)

    Each rule begins with a name (which is the name defined by the rule) and ::=. A vertical bar (|) is used to separate alternatives; it is the least binding operator in this notation. A star (*) means zero or more repetitions of the preceding item; likewise, a plus (+) means one or more repetitions, and a phrase enclosed in square brackets ([ ]) means zero or one occurrences (in other words, the enclosed phrase is optional). The * and + operators bind as tightly as possible; parentheses are used for grouping. Literal strings are enclosed in quotes. White space is only meaningful to separate tokens. Rules are normally contained on a single line; rules with many alternatives may be formatted alternatively with each line after the first beginning with a vertical bar.

    In lexical definitions (as the example above), two more conventions are used: Two literal characters separated by three dots mean a choice of any single character in the given (inclusive) range of ASCII characters. A phrase between angular brackets (<...>) gives an informal description of the symbol defined; e.g., this could be used to describe the notion of ‘control character’ if needed.

    Even though the notation used is almost the same, there is a big difference between the meaning of lexical and syntactic definitions: a lexical definition operates on the individual characters of the input source, while a syntax definition operates on the stream of tokens generated by the lexical analysis. All uses of BNF in the next chapter (“Lexical Analysis”) are lexical definitions; uses in subsequent chapters are syntactic definitions.

     

    첫 번째 줄은 이름이 lc_letter이고 그 뒤에 0개 이상의 lc_letters와 밑줄이 순서대로 있음을 나타낸다. lc_letter는 'a'부터 'z'까지의 단일 문자 중 하나이다. (이 규칙은 이 문서의 어휘 및 문법 규칙에 정의된 이름에 대해 실제로 준수된다.)

    각 규칙은 이름(규칙에 의해 정의된 이름)과 ::=으로 시작된다. 세로 막대(|)는 대안을 구분하는 데 사용된다. 이 표기법에서 최소 바인딩 연산자이다. 별표(*)는 이전 항목이 0회 이상 반복됨을 의미한다. 마찬가지로 더하기(+)는 1회 이상의 반복을 의미하고 대괄호([ ])로 묶인 구는 0회 또는 1회 발생을 의미한다(즉, 괄호 안의 구는 선택사항임). * 및 + 연산자는 가능한 한 단단히 바인딩된다. 괄호는 그룹화에 사용된다. 리터럴 문자열은 따옴표로 묶인다. 공백은 토큰을 구분하는 데에만 의미가 있다. 규칙은 일반적으로 한 줄에 포함된다. 대안이 많은 규칙은 수직 막대로 처음 시작하는 줄 이후에 각 줄을 사용하여 형식을 지정할 수 있다.

    위의 예와 같이 어휘 정의에서는 두 가지 규칙이 더 사용된다. 세 개의 점으로 구분된 두 개의 리터럴 문자는 지정된(포함) ASCII 문자 범위에서 단일 문자를 선택한다는 의미다. 꺾쇠 괄호(<...>) 사이의 구문은 정의된 기호에 대한 비공식적 설명을 제공한다. 예를 들어, 필요한 경우 '제어 문자' 개념을 설명하는 데 사용될 수 있다.

    사용된 표기법은 거의 동일하지만 어휘 정의와 구문 정의의 의미에는 큰 차이가 있다. 어휘 정의는 입력 소스의 개별 문자에 대해 작동하는 반면 구문 정의는 어휘 분석에 의해 생성된 토큰 스트림에서 작동한다. 다음 장("어휘 분석")에서 모든 BNF의 사용은 어휘 정의이다. 후속 장의 사용은 구문 정의이다.

     

    Python/Reference/어휘분석

     

    Python/Reference/어휘분석

    파이썬을 사용하면서 파이썬 매뉴얼을 참고해야 할 경우가 있다. 이럴 경우 매뉴얼의 구성과 용어에 대해 알고 접근하는 것이 도움이 된다. 그래서 매뉴얼을 설명하는 챕터 1과 2를 번역해 올린

    summertrees.tistory.com

     

    728x90

    댓글

Designed by Tistory.