728x90
반응형
예제 코드
if __name__ == "__main__":
import sys
with Database() as db:
if len(sys.argv) > 1:
method_name = sys.argv[1]
method = getattr(db, method_name, None)
args = sys.argv[2:] # Get additional arguments
if method is not None and callable(method):
method(*args) # Pass the arguments to the method
else:
print(f"Method {method_name} not found")
위 script의 경로가 project/a/b.py 라고 하자
method가 될 함수는 create_table,
argument는 users.sql 인 경우에
아래와 같이 create_table을 다음과 같이 인자를 주면서 스크립트로 실행 가능
python -m a.b create_table users.sql
예제 커밋: https://github.com/Junanjunan/fmp/commit/b886a386e4268dce9faafd51828c8bdad12151d1
728x90
반응형