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
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
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
- Ask for {{source_code}} and its source language if not provided.
- Convert the code to Python, preserving the original logic, control flow and behavior exactly — do not "improve" the logic unless asked.
- Use idiomatic Python patterns (list comprehensions, context managers, etc.) rather than a literal line-by-line translation, where it doesn't change behavior.
- Add inline comments explaining any non-obvious conversion decisions, especially where the source language's semantics differ from Python's.
- 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.