메이커링크

ChatGPT 활용 Python 코드 생성 프롬프트 엔지니어링 레시피

ChatGPT를 활용하여 특정 기능을 수행하는 Python 코드를 빠르고 정확하게 생성하기 위한 구체적인 프롬프트 작성 방법을 안내합니다. 개발 생산성 향상에 도움을 줍니다.

#chatgpt#python#code generation#prompt engineering#ai

ChatGPT 활용 Python 코드 생성 프롬프트 엔지니어링

이 레시피는 ChatGPT를 사용하여 특정 요구사항에 맞는 Python 코드를 효과적으로 생성하기 위한 프롬프트 작성 가이드입니다. 아래 양식을 복사하여 필요한 부분을 구체적인 요구사항으로 채워 사용하세요.

프롬프트 템플릿:

You are an expert Python developer. Generate a Python code snippet that fulfills the following requirements:

1.  **Core Functionality:** Describe the main task the code should perform. For example: "Read data from a CSV file named 'data.csv' and calculate the average of a column named 'value'."
2.  **Input:** Specify any required inputs. For example: "The CSV file 'data.csv' is located in the same directory as the script. The file has a header row."
3.  **Output:** Define the expected output. For example: "Print the calculated average to the console, formatted to two decimal places."
4.  **Libraries/Frameworks:** List any specific libraries or frameworks to use. For example: "Use the pandas library for data manipulation."
5.  **Error Handling:** Specify any error handling requirements. For example: "Handle potential FileNotFoundError if 'data.csv' does not exist. Print an informative error message."
6.  **Constraints/Specifics:** Include any other relevant constraints or details. For example: "Assume the 'value' column contains only numeric data. The script should be runnable directly."

Provide only the Python code, enclosed in markdown code blocks. Do not include any explanations before or after the code block.

예시 적용:

만약 'users.json' 파일에서 사용자 정보를 읽어와 ID가 101인 사용자의 'email' 주소를 출력하는 Python 코드를 생성하고 싶다면, 위 템플릿의 각 항목을 다음과 같이 채울 수 있습니다:

  1. Core Functionality: "Read user data from a JSON file named 'users.json' and retrieve the email address of the user with 'id' equal to 101."
  2. Input: "The 'users.json' file is located in the same directory as the script. The file contains a list of user objects, each with an 'id' and 'email' field."
  3. Output: "Print the email address of the user with id 101 to the console. If the user is not found, print 'User with ID 101 not found.'"
  4. Libraries/Frameworks: "Use the built-in 'json' library for parsing the JSON file."
  5. Error Handling: "Handle potential FileNotFoundError if 'users.json' does not exist. Handle potential JSONDecodeError if the file content is invalid JSON."
  6. Constraints/Specifics: "The script should be a single file and runnable directly."

이와 같이 구체적인 요구사항을 명확하게 제시하면 ChatGPT는 더욱 정확하고 유용한 코드를 생성할 수 있습니다.

3
스크랩
18
좋아요

메이커링크 에이전트

이 레시피, 직접 따라 하지 말고 맡겨 보세요

휴대폰에서 한 줄로 지시하면 메이커링크 에이전트가 내 PC의 Cursor · Claude Code로 그대로 실행합니다.

무료로 시작하기 원격 PC 1대 무료 · 내 AI 구독 그대로

함께 보면 좋은 레시피

AI 레시피

Cursor AI를 활용한 코드 리팩토링 및 성능 최적화 가이드

Cursor의 AI 코딩 어시스턴트를 사용하여 코드의 가독성을 높이고, 실행 속도를 개선하며, 메모리 사용량을 줄이는 방법을 단계별로 안내합니다. 코드 품질 향상을 위한 실질적인 팁을 제공합니다.

#code refactoring#performance optimization

터미널 레시피

RESTful API 기본 구조 및 인증 토큰 검증 CLI 레시피

RESTful API의 기본 GET, POST 요청을 보내고, Authorization 헤더에 Bearer 토큰을 포함하여 서버 응답을 확인하는 CLI 명령어입니다. API 개발 및 테스트에 유용합니다.

#curl#restful api

AI 레시피

GitOps 기반 Kubernetes 자동 배포 파이프라인 구축 가이드

GitOps 원칙을 사용하여 Kubernetes 환경에 애플리케이션을 자동으로 배포하고 관리하는 방법을 안내합니다. CI/CD와 Git의 장점을 결합한 효율적인 배포 전략을 이해하고 적용하는 데 도움이 됩니다.

#gitops#kubernetes

터미널 레시피

Helm으로 Kubernetes 애플리케이션 패키징 및 기본 배포

Helm 차트를 생성하고 로컬 Kubernetes 클러스터에 간단한 애플리케이션을 배포하는 과정을 보여주는 명령어 레시피입니다. CI/CD 파이프라인 연동의 기초로 활용할 수 있습니다.

#helm#kubernetes

AI 레시피

SQL vs NoSQL 데이터베이스 비교 및 선택 가이드

SQL과 NoSQL 데이터베이스의 핵심적인 차이점을 이해하고, 프로젝트 요구사항에 맞는 데이터베이스를 선택하는 데 도움을 주는 가이드입니다.

#sql#nosql

AI 레시피

GitOps 핵심 개념과 CI/CD 파이프라인 구축 전략 가이드

GitOps의 기본 원리를 이해하고, Docker, Kubernetes, GitHub Actions를 활용하여 자동화된 CI/CD 파이프라인을 구축하는 방법을 안내합니다. 실무 적용에 필요한 핵심 개념과 전략을 다룹니다.

#gitops#cicd