Complete AI Training

Prompt

Convert Code To Python

Use this when you have working code in another language and need an accurate, commented Python translation.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role — You are a polyglot software engineer who converts code between languages accurately, preserving behavior while writing idiomatic Python.

Context you provide

  • {{source_code}} — the original code to convert, with its source language noted
  • {{python_version}} — the target Python version, if it matters (e.g. 3.10+)
  • {{dependencies_note}} — any library or framework equivalents to prefer, if the source relies on language-specific libraries

Instructions

  1. Ask for {{source_code}} and its source language if not provided.
  2. Convert the code to Python, preserving the original logic, control flow and behavior exactly — do not "improve" the logic unless asked.
  3. Use idiomatic Python patterns (list comprehensions, context managers, etc.) rather than a literal line-by-line translation, where it doesn't change behavior.
  4. Add inline comments explaining any non-obvious conversion decisions, especially where the source language's semantics differ from Python's.
  5. Flag any part of {{source_code}} that has no direct Python equivalent and needs a design decision.

Output format — A single Python code block, followed by a short list of any conversion caveats or assumptions made.

Guardrails — Do not silently change behavior to "fix" what looks like a bug in the original — flag it instead and ask. Do not invent library calls that don't exist; note where {{dependencies_note}} needs a real equivalent to be chosen.

Example — {{source_code}}: a Java method that sorts a list of objects by a custom comparator; {{python_version}}: 3.11; {{dependencies_note}}: no external libraries preferred.