
REPL shell
python
- Python 인터프리터를 실행하여
- 사용자가 명령을 한 줄씩 입력하면 즉시 실행 결과를 반환하는 방식
- Interactive Execution (REPL: Read–Eval–Print Loop) 이라고 불림.
Script Execution
python <main_script_file>.py
- Python 인터프리터가 지정된
<main_script_file>.py파일을 읽어 - 하나의 프로그램으로 실행하는 방식
- Running a Python Script 가 바로 이 방식을 의미함.
- 실행할 main sciprt file은 PATH로 지정
https://dsaint31.tistory.com/222
Path (경로)
파일 시스템 내에서 특정 파일(혹은 디렉토리)의 위치를 나타내는 문자열Absolute Path (절대 경로)현 작업디렉토리(cwd)와 관계없이 절대적 위치드라이브:\폴더\폴더\파일명 (Windows)c:\Windows\System32\dri
dsaint31.tistory.com
Module Execution
python -m <module_name>
- Python 인터프리터가
sys.path(정확히는 module search path)에서 <module_name>이라는 이름을 가지는 모듈을 찾아- 해당 모듈을
__main__컨텍스트로 실행하는 방식. - Running a Module with
-m이 바로 이 방식임.
참고로, 확장자
.py로 끝나는 파이썬 소스코드 파일이 module에 해당하며,
해당 파일의 이름이 곧 해당 module의 이름이 된다.
디렉토리등을 통해 패키지(또는 상위 모듈명) 명이 앞에 붙게되며 이들간 구분은 period로 이루어짐.
module search path는 다음의 명령어로 확인 가능하며,
module execution 의 경우 실행이 이루어진 현재 디렉토리(current working directory)는 항상 module search path에 포함됨.
python -c "import sys;print(sys.path)"
moduel search path에 대해 보다 자세한 내용은 다음을 참고:
https://dsaint31.tistory.com/528
[Python] Module Search Path and sys.path
Module Search Path and sys.path1. Module Search PathPython 에서 module을 찾는 경로 (Module Search Path)는 다음의 순서별로 우선권을 가짐.home directory of the program (main script file이 있는 위치 or python shell이 수행된 cwd)m
dsaint31.tistory.com
Command Execution
python -c "<python_codes>"
- Python 인터프리터가 명령줄(commnad line)에 전달된 문자열(위의 예에서
"<python_codes>")을 - Python 코드로 해석하여 즉시 실행하는 방식
-coption)** 또는 Command-line Code Execution 이라고 불림.
앞서 module search path를 확인하는 예제에서 사용된 방식이며, 쌍따옴표 내에서 statement구분은 ;으로 할 수 있음.
2023.09.12 - [Linux] - [Linux] Pipe(|)와 다중 명령어 (;, &&, ||)
[Linux] Pipe(|)와 다중 명령어 (;, &&, ||)
| : PipePipe |는 2개의 processes를 연결해주는 연결 통로로서pipe 앞의 프로세스의 stdout(표준출력)이pipe 뒤의 프로세스의 stdin(표준입력)으로 쓰이도록 연결해주는 것임. 예를 들어 ls|sort|more의 경우 ls
ds31x.tistory.com
Script Execution with Interactive Mode
python -i <main_script_file>.py
- 스크립트를 Script Execution 방식으로 먼저 실행한 후,
- 종료 뒤에도 인터프리터를 유지하여 REPL로 진입하는 방식
-ioption 방식이라고도 부름.
같이 보면 좋은 자료들
https://dsaint31.tistory.com/entry/Python-Python-Interactive-Shell
[Python] Python Interactive Shell (or Python Interactive Prompt)
REPL or Interactive ModePython을 가장 쉽게 (또는 naive하게) 사용하는 방법은 Python Shell을 통해 사용하는 것임.엄밀하게 애기하면 Python Interactive Session에서 실행하는 것 임.더보기Session은 특정 사용자 (또
dsaint31.tistory.com
https://dsaint31.tistory.com/504
[Python] Python Script File 실행해보기
1. Python Script File (=main script file)의 구조다음은 일반적인 Python script file의 전형적인 구조 를 간략히 나타냄. (고정된 것은 아님.)이미 구현된 기능 등을 사용하기 위해 외부 library 와 module을 import함
dsaint31.tistory.com
'Python' 카테고리의 다른 글
| Python Data Model (+ Metaclass) (0) | 2026.02.25 |
|---|---|
| Hook 이란? (0) | 2026.02.23 |
| Python Class Definition and Object Model (0) | 2025.12.24 |
| PyPI에 wheel을 업로드하기 (0) | 2025.12.21 |
| 개발 디렉토리를 pip package로 설치하기 - pip install -e . (0) | 2025.12.21 |