AI CodingThrive Editorial

25 prompt IA per programmare in Python

Un assistente può scrivere Python rapidamente, ma il risultato utile è una funzione circoscritta, con tipi espliciti, esempi e test. Questi prompt chiariscono le ipotesi prima del codice.

13 min di letturaAggiornato
Scrivania di uno sviluppatore Python con portatile, taccuino e forme astratte di codice.

La versione breve

  • Un assistente può scrivere Python rapidamente, ma il risultato utile è una funzione circoscritta, con tipi espliciti, esempi e test. Questi prompt chiariscono le ipotesi prima del codice.
  • Non incollare credenziali, dati privati dei clienti o interi repository proprietari in un assistente non autorizzato. Esegui i comandi e i test proposti nel tuo ambiente. Una patch plausibile non dimostra che la modifica funzioni.

Un assistente può scrivere Python rapidamente, ma il risultato utile è una funzione circoscritta, con tipi espliciti, esempi e test. Questi prompt chiariscono le ipotesi prima del codice.

Non incollare credenziali, dati privati dei clienti o interi repository proprietari in un assistente non autorizzato. Esegui i comandi e i test proposti nel tuo ambiente. Una patch plausibile non dimostra che la modifica funzioni.

Come usare questa raccolta

Scegli l'attività più vicina al tuo lavoro. Copia il prompt, sostituisci la scena generica o il contesto del codice con i tuoi dati e mantieni i vincoli utili a valutare il risultato. Modifica una variabile alla volta per capire cosa migliora.

Il metodo segue la guida al prompt engineering di GitHub Copilot: fornisci un contesto preciso e controlla il risultato, senza dare per corretta una prima bozza ben presentata.

Prompt per la diagnosi

Questa sezione riguarda la diagnosi dei problemi. Fornisci il codice reale e il comando di test prima di accettare la risposta.

1. Un importatore CSV

Help with a CSV importer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

2. Una funzione per normalizzare le date

Help with a date normalization utility in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

3. Un parser di log

Help with a log parser in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

4. Un client HTTP con nuovi tentativi

Help with a retrying HTTP client in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

5. Un report dalla riga di comando

Help with a command-line report in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

6. Uno strumento per individuare duplicati

Help with a duplicate detector in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

7. Uno strumento per rinominare file

Help with a file renamer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

8. Un livello di validazione dei dati

Help with a data validation layer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

9. Un'attività in background

Help with a background task in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

CSV records passing through a Python validation workflow.

10. Un refactoring da notebook a modulo

Help with a notebook-to-module refactor in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui il caso di riproduzione proposto prima di applicare una patch.

Prompt per l'implementazione

Questa sezione riguarda l'implementazione. Fornisci il codice reale e il comando di test prima di accettare la risposta.

11. Un importatore CSV

Help with a CSV importer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

12. Una funzione per normalizzare le date

Help with a date normalization utility in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

13. Un parser di log

Help with a log parser in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

14. Un client HTTP con nuovi tentativi

Help with a retrying HTTP client in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

15. Un report dalla riga di comando

Help with a command-line report in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

16. Uno strumento per individuare duplicati

Help with a duplicate detector in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

17. Uno strumento per rinominare file

Help with a file renamer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

Three-step code workflow: brief the work, inspect the result, edit and verify.

18. Un livello di validazione dei dati

Help with a data validation layer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

19. Un'attività in background

Help with a background task in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

20. Un refactoring da notebook a modulo

Help with a notebook-to-module refactor in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Controlla nella patch le modifiche non pertinenti e gli accessi ai dati non previsti.

Prompt per i casi limite

Questa sezione riguarda i test dei casi limite. Fornisci il codice reale e il comando di test prima di accettare la risposta.

21. Un importatore CSV

Help with a CSV importer in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui i test e, quando possibile, verifica che falliscano prima della correzione.

22. Una funzione per normalizzare le date

Help with a date normalization utility in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui i test e, quando possibile, verifica che falliscano prima della correzione.

23. Un parser di log

Help with a log parser in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui i test e, quando possibile, verifica che falliscano prima della correzione.

24. Un client HTTP con nuovi tentativi

Help with a retrying HTTP client in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui i test e, quando possibile, verifica che falliscano prima della correzione.

25. Un report dalla riga di comando

Help with a command-line report in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verifica: Esegui i test e, quando possibile, verifica che falliscano prima della correzione.

Cosa verificare prima di usare il risultato

Non incollare credenziali, dati privati dei clienti o interi repository proprietari in un assistente non autorizzato. Esegui i comandi e i test proposti nel tuo ambiente. Una patch plausibile non dimostra che la modifica funzioni.

Se il risultato non risponde al compito, accorcia il prompt e precisa il fatto o il vincolo mancante. Conserva la versione usata per poter riprodurre il contenuto finale o la modifica al codice.

Approfondimenti

Continua con una guida correlata

Mettilo in pratica

Il prossimo passo

Hai una domanda o una correzione?

Contatta Thrive

Continua a leggere

Altri articoli del blog

Tutti gli articoli