# SOME DESCRIPTIVE TITLE. # Copyright (C) 2001-2019, Python Software Foundation # This file is distributed under the same license as the Python package. # FIRST AUTHOR , YEAR. # msgid "" msgstr "" "Project-Id-Version: Python 3.7\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2024-06-01 22:23+0200\n" "PO-Revision-Date: 2024-05-30 09:19+0200\n" "Last-Translator: Alessandro Cucci \n" "Language-Team: \n" "Language: it_IT\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Poedit 2.2.1\n" #: tutorial/errors.rst:5 msgid "Errors and Exceptions" msgstr "Errori ed Eccezioni" #: tutorial/errors.rst:7 msgid "" "Until now error messages haven't been more than mentioned, but if you have " "tried out the examples you have probably seen some. There are (at least) " "two distinguishable kinds of errors: *syntax errors* and *exceptions*." msgstr "" "Finora i messaggi di errore sono stati solo menzionati, ma se hai provato " "gli esempi probabilmente ne hai visti alcuni. Ci sono (almeno) due tipi " "distinti di errori: *errori di sintassi* ed *eccezioni*." #: tutorial/errors.rst:15 msgid "Syntax Errors" msgstr "Errori di Sintassi" #: tutorial/errors.rst:17 msgid "" "Syntax errors, also known as parsing errors, are perhaps the most common " "kind of complaint you get while you are still learning Python::" msgstr "" "Gli errori di sintassi, noti anche come errori di parsing, sono forse il " "tipo più comune di reclamo che si ottiene mentre si sta ancora imparando " "Python::" #: tutorial/errors.rst:26 msgid "" "The parser repeats the offending line and displays little 'arrow's pointing " "at the token in the line where the error was detected. The error may be " "caused by the absence of a token *before* the indicated token. In the " "example, the error is detected at the function :func:`print`, since a colon " "(``':'``) is missing before it. File name and line number are printed so " "you know where to look in case the input came from a script." msgstr "" "Il parser ripete la linea incriminata e mostra delle piccole 'freccette' che " "puntano al token nella linea in cui è stato rilevato l'errore. L'errore può " "essere causato dall'assenza di un token *prima* del token indicato. " "Nell'esempio, l'errore è rilevato alla funzione :func:`print`, poiché manca " "un due punti (``':'``) prima di essa. Vengono stampati il nome del file e il " "numero di linea in modo che si sappia dove cercare nel caso in cui l'input " "provenga da uno script." #: tutorial/errors.rst:37 msgid "Exceptions" msgstr "Eccezioni" #: tutorial/errors.rst:39 msgid "" "Even if a statement or expression is syntactically correct, it may cause an " "error when an attempt is made to execute it. Errors detected during " "execution are called *exceptions* and are not unconditionally fatal: you " "will soon learn how to handle them in Python programs. Most exceptions are " "not handled by programs, however, and result in error messages as shown " "here::" msgstr "" "Anche se un'istruzione o un'espressione è sintatticamente corretta, può " "causare un errore quando si tenta di eseguirla. Gli errori rilevati durante " "l'esecuzione sono chiamati *eccezioni* e non sono incondizionatamente " "fatali: imparerai presto come gestirli nei programmi Python. La maggior " "parte delle eccezioni non viene gestita dai programmi, tuttavia, e si " "traduce in messaggi di errore come mostrato qui::" #: tutorial/errors.rst:58 msgid "" "The last line of the error message indicates what happened. Exceptions come " "in different types, and the type is printed as part of the message: the " "types in the example are :exc:`ZeroDivisionError`, :exc:`NameError` and :exc:" "`TypeError`. The string printed as the exception type is the name of the " "built-in exception that occurred. This is true for all built-in exceptions, " "but need not be true for user-defined exceptions (although it is a useful " "convention). Standard exception names are built-in identifiers (not reserved " "keywords)." msgstr "" "L'ultima linea del messaggio di errore indica cosa è successo. Le eccezioni " "hanno tipi diversi, e il tipo viene stampato come parte del messaggio: i " "tipi nell'esempio sono :exc:`ZeroDivisionError`, :exc:`NameError` e :exc:" "`TypeError`. La stringa stampata come tipo di eccezione è il nome " "dell'eccezione built-in che si è verificata. Questo è vero per tutte le " "eccezioni built-in, ma non deve essere vero per le eccezioni definite " "dall'utente (anche se è una convenzione utile). I nomi delle eccezioni " "standard sono identificatori built-in (non parole chiave riservate)." #: tutorial/errors.rst:66 msgid "" "The rest of the line provides detail based on the type of exception and what " "caused it." msgstr "" "La restante parte della linea fornisce dettagli basati sul tipo di eccezione " "e su cosa l'ha causata." #: tutorial/errors.rst:69 msgid "" "The preceding part of the error message shows the context where the " "exception occurred, in the form of a stack traceback. In general it contains " "a stack traceback listing source lines; however, it will not display lines " "read from standard input." msgstr "" "La parte precedente del messaggio di errore mostra il contesto in cui si è " "verificata l'eccezione, sotto forma di traccia dello stack. In generale, " "contiene una traccia dello stack che elenca le linee di origine; tuttavia, " "non visualizzerà linee lette dall'input standard." #: tutorial/errors.rst:74 msgid "" ":ref:`bltin-exceptions` lists the built-in exceptions and their meanings." msgstr "" ":ref:`bltin-exceptions` elenca le eccezioni built-in e i loro significati." #: tutorial/errors.rst:80 msgid "Handling Exceptions" msgstr "Gestione delle Eccezioni" #: tutorial/errors.rst:82 msgid "" "It is possible to write programs that handle selected exceptions. Look at " "the following example, which asks the user for input until a valid integer " "has been entered, but allows the user to interrupt the program (using :kbd:" "`Control-C` or whatever the operating system supports); note that a user-" "generated interruption is signalled by raising the :exc:`KeyboardInterrupt` " "exception. ::" msgstr "" "È possibile scrivere programmi che gestiscono eccezioni selezionate. Guarda " "il seguente esempio, che chiede all'utente un input finché non viene " "inserito un intero valido, ma consente all'utente di interrompere il " "programma (usando :kbd:`Control-C` o cosa supporta il sistema operativo); " "nota che un'interruzione generata dall'utente è segnalata sollevando " "l'eccezione :exc:`KeyboardInterrupt`. ::" #: tutorial/errors.rst:96 msgid "The :keyword:`try` statement works as follows." msgstr "L'istruzione :keyword:`try` funziona come segue." #: tutorial/errors.rst:98 msgid "" "First, the *try clause* (the statement(s) between the :keyword:`try` and :" "keyword:`except` keywords) is executed." msgstr "" "Per prima cosa, viene eseguita la *clausola try* (l'istruzione o le " "istruzioni tra le parole chiave :keyword:`try` e :keyword:`except`)." #: tutorial/errors.rst:101 msgid "" "If no exception occurs, the *except clause* is skipped and execution of the :" "keyword:`try` statement is finished." msgstr "" "Se non si verifica alcuna eccezione, la *clausola except* viene saltata e " "l'esecuzione dell'istruzione :keyword:`try` è terminata." #: tutorial/errors.rst:104 msgid "" "If an exception occurs during execution of the :keyword:`try` clause, the " "rest of the clause is skipped. Then, if its type matches the exception " "named after the :keyword:`except` keyword, the *except clause* is executed, " "and then execution continues after the try/except block." msgstr "" "Se si verifica un'eccezione durante l'esecuzione della clausola :keyword:" "`try`, il resto della clausola viene saltato. Poi, se il suo tipo " "corrisponde all'eccezione nominata dopo la parola chiave :keyword:`except`, " "viene eseguita la *clausola except*, e quindi l'esecuzione continua dopo il " "blocco try/except." #: tutorial/errors.rst:109 msgid "" "If an exception occurs which does not match the exception named in the " "*except clause*, it is passed on to outer :keyword:`try` statements; if no " "handler is found, it is an *unhandled exception* and execution stops with an " "error message." msgstr "" "Se si verifica un'eccezione che non corrisponde all'eccezione nominata nella " "*clausola except*, viene passata alle istruzioni :keyword:`try` esterne; se " "non viene trovato alcun gestore, è un' *eccezione non gestita* e " "l'esecuzione si interrompe con un messaggio di errore." #: tutorial/errors.rst:113 msgid "" "A :keyword:`try` statement may have more than one *except clause*, to " "specify handlers for different exceptions. At most one handler will be " "executed. Handlers only handle exceptions that occur in the corresponding " "*try clause*, not in other handlers of the same :keyword:`!try` statement. " "An *except clause* may name multiple exceptions as a parenthesized tuple, " "for example::" msgstr "" "Un'istruzione :keyword:`try` può avere più di una *clausola except*, per " "specificare gestori per diverse eccezioni. Al massimo verrà eseguito un " "gestore. I gestori gestiscono solo le eccezioni che si verificano nella " "corrispondente *clausola try*, non in altri gestori della stessa istruzione :" "keyword:`!try`. Una *clausola except* può nominare più eccezioni come una " "tupla tra parentesi, per esempio::" #: tutorial/errors.rst:122 msgid "" "A class in an :keyword:`except` clause matches exceptions which are " "instances of the class itself or one of its derived classes (but not the " "other way around --- an *except clause* listing a derived class does not " "match instances of its base classes). For example, the following code will " "print B, C, D in that order::" msgstr "" "Una classe in una clausola :keyword:`except` corrisponde a eccezioni che " "sono istanze della classe stessa o di una delle sue classi derivate (ma non " "viceversa --- una *clausola except* che elenca una classe derivata non " "corrisponde a istanze delle sue classi base). Ad esempio, il seguente codice " "stamperà B, C, D in quell'ordine::" #: tutorial/errors.rst:146 msgid "" "Note that if the *except clauses* were reversed (with ``except B`` first), " "it would have printed B, B, B --- the first matching *except clause* is " "triggered." msgstr "" "Nota che se le *clausole except* fossero invertite (con ``except B`` prima), " "avrebbero stampato B, B, B --- la prima *clausola except* che corrisponde " "viene attivata." #: tutorial/errors.rst:149 msgid "" "When an exception occurs, it may have associated values, also known as the " "exception's *arguments*. The presence and types of the arguments depend on " "the exception type." msgstr "" "Quando si verifica un'eccezione, essa può avere valori associati, noti anche " "come *argomenti* dell'eccezione. La presenza e il tipo degli argomenti " "dipendono dal tipo di eccezione." #: tutorial/errors.rst:153 msgid "" "The *except clause* may specify a variable after the exception name. The " "variable is bound to the exception instance which typically has an ``args`` " "attribute that stores the arguments. For convenience, builtin exception " "types define :meth:`~object.__str__` to print all the arguments without " "explicitly accessing ``.args``. ::" msgstr "" "La *clausola except* può specificare una variabile dopo il nome " "dell'eccezione. La variabile è legata all'istanza dell'eccezione che " "tipicamente ha un attributo ``args`` che memorizza gli argomenti. Per " "comodità, i tipi di eccezioni built-in definiscono :meth:`~object.__str__` " "per stampare tutti gli argomenti senza accedere esplicitamente a ``." "args``. ::" #: tutorial/errors.rst:176 msgid "" "The exception's :meth:`~object.__str__` output is printed as the last part " "('detail') of the message for unhandled exceptions." msgstr "" "L'output di :meth:`~object.__str__` dell'eccezione viene stampato come " "l'ultima parte ('dettaglio') del messaggio per le eccezioni non gestite." #: tutorial/errors.rst:179 msgid "" ":exc:`BaseException` is the common base class of all exceptions. One of its " "subclasses, :exc:`Exception`, is the base class of all the non-fatal " "exceptions. Exceptions which are not subclasses of :exc:`Exception` are not " "typically handled, because they are used to indicate that the program should " "terminate. They include :exc:`SystemExit` which is raised by :meth:`sys." "exit` and :exc:`KeyboardInterrupt` which is raised when a user wishes to " "interrupt the program." msgstr "" ":exc:`BaseException` è la classe base comune di tutte le eccezioni. Uno dei " "suoi sottosclassi, :exc:`Exception`, è la classe base di tutte le eccezioni " "non fatali. Le eccezioni che non sono sottoclassi di :exc:`Exception` non " "sono tipicamente gestite, perché vengono utilizzate per indicare che il " "programma dovrebbe terminare. Queste includono :exc:`SystemExit` che è " "sollevata da :meth:`sys.exit` e :exc:`KeyboardInterrupt` che è sollevata " "quando un utente desidera interrompere il programma." #: tutorial/errors.rst:187 msgid "" ":exc:`Exception` can be used as a wildcard that catches (almost) everything. " "However, it is good practice to be as specific as possible with the types of " "exceptions that we intend to handle, and to allow any unexpected exceptions " "to propagate on." msgstr "" ":exc:`Exception` può essere utilizzata come un jolly che cattura (quasi) " "tutto. Tuttavia, è buona pratica essere il più specifici possibile con i " "tipi di eccezioni che intendiamo gestire, e permettere a qualsiasi eccezione " "inattesa di propagarsi." #: tutorial/errors.rst:192 msgid "" "The most common pattern for handling :exc:`Exception` is to print or log the " "exception and then re-raise it (allowing a caller to handle the exception as " "well)::" msgstr "" "Il pattern più comune per la gestione di :exc:`Exception` è stamparla o " "registrarla e poi rilanciarla (consentendo a un chiamante di gestire " "l'eccezione altrettanto)::" #: tutorial/errors.rst:210 msgid "" "The :keyword:`try` ... :keyword:`except` statement has an optional *else " "clause*, which, when present, must follow all *except clauses*. It is " "useful for code that must be executed if the *try clause* does not raise an " "exception. For example::" msgstr "" "L'istruzione :keyword:`try` ... :keyword:`except` ha una *clausola else* " "opzionale, che, quando presente, deve seguire tutte le *clausole except*. È " "utile per il codice che deve essere eseguito se la *clausola try* non " "solleva un'eccezione. Per esempio::" #: tutorial/errors.rst:224 msgid "" "The use of the :keyword:`!else` clause is better than adding additional code " "to the :keyword:`try` clause because it avoids accidentally catching an " "exception that wasn't raised by the code being protected by the :keyword:`!" "try` ... :keyword:`!except` statement." msgstr "" "L'uso della clausola :keyword:`!else` è migliore che aggiungere codice " "ulteriore alla clausola :keyword:`try` perché evita di catturare " "accidentalmente un'eccezione che non è stata sollevata dal codice protetto " "dall'istruzione :keyword:`!try` ... :keyword:`!except`." #: tutorial/errors.rst:229 msgid "" "Exception handlers do not handle only exceptions that occur immediately in " "the *try clause*, but also those that occur inside functions that are called " "(even indirectly) in the *try clause*. For example::" msgstr "" "I gestori delle eccezioni non gestiscono solo le eccezioni che si verificano " "immediatamente nella *clausola try*, ma anche quelle che si verificano " "all'interno delle funzioni che vengono chiamate (anche indirettamente) nella " "*clausola try*. Per esempio::" #: tutorial/errors.rst:247 msgid "Raising Exceptions" msgstr "Sollevare Eccezioni" #: tutorial/errors.rst:249 msgid "" "The :keyword:`raise` statement allows the programmer to force a specified " "exception to occur. For example::" msgstr "" "L'istruzione :keyword:`raise` permette al programmatore di forzare il " "verificarsi di una specifica eccezione. Per esempio::" #: tutorial/errors.rst:257 msgid "" "The sole argument to :keyword:`raise` indicates the exception to be raised. " "This must be either an exception instance or an exception class (a class " "that derives from :class:`BaseException`, such as :exc:`Exception` or one of " "its subclasses). If an exception class is passed, it will be implicitly " "instantiated by calling its constructor with no arguments::" msgstr "" "L'unico argomento per :keyword:`raise` indica l'eccezione da sollevare. " "Questo deve essere o un'istanza di eccezione o una classe di eccezione (una " "classe che deriva da :class:`BaseException`, come :exc:`Exception` o una " "delle sue sottoclassi). Se viene passata una classe di eccezione, verrà " "istanziata implicitamente chiamando il suo costruttore senza argomenti::" #: tutorial/errors.rst:265 msgid "" "If you need to determine whether an exception was raised but don't intend to " "handle it, a simpler form of the :keyword:`raise` statement allows you to re-" "raise the exception::" msgstr "" "Se è necessario determinare se un'eccezione è stata sollevata ma non si " "intende gestirla, una forma più semplice dell'istruzione :keyword:`raise` " "consente di rilanciare l'eccezione::" #: tutorial/errors.rst:284 msgid "Exception Chaining" msgstr "Collegamento delle Eccezioni" #: tutorial/errors.rst:286 msgid "" "If an unhandled exception occurs inside an :keyword:`except` section, it " "will have the exception being handled attached to it and included in the " "error message::" msgstr "" "Se si verifica un'eccezione non gestita all'interno di una sezione :keyword:" "`except`, avrà l'eccezione che viene gestita allegata e inclusa nel " "messaggio di errore::" #: tutorial/errors.rst:305 msgid "" "To indicate that an exception is a direct consequence of another, the :" "keyword:`raise` statement allows an optional :keyword:`from` clause::" msgstr "" "Per indicare che un'eccezione è una diretta conseguenza di un'altra, " "l'istruzione :keyword:`raise` permette una clausola opzionale :keyword:" "`from`::" #: tutorial/errors.rst:311 msgid "This can be useful when you are transforming exceptions. For example::" msgstr "" "Questo può essere utile quando si stanno trasformando le eccezioni. Per " "esempio::" #: tutorial/errors.rst:332 msgid "" "It also allows disabling automatic exception chaining using the ``from " "None`` idiom::" msgstr "" "Consente anche di disabilitare il collegamento automatico delle eccezioni " "utilizzando l'idioma ``from None``::" #: tutorial/errors.rst:344 msgid "" "For more information about chaining mechanics, see :ref:`bltin-exceptions`." msgstr "" "Per ulteriori informazioni sulla meccanica del collegamento, vedi :ref:" "`bltin-exceptions`." #: tutorial/errors.rst:350 msgid "User-defined Exceptions" msgstr "Eccezioni Definite dall'Utente" #: tutorial/errors.rst:352 msgid "" "Programs may name their own exceptions by creating a new exception class " "(see :ref:`tut-classes` for more about Python classes). Exceptions should " "typically be derived from the :exc:`Exception` class, either directly or " "indirectly." msgstr "" "I programmi possono nominare le proprie eccezioni creando una nuova classe " "di eccezione (vedi :ref:`tut-classes` per ulteriori informazioni sulle " "classi Python). Le eccezioni devono essere tipicamente derivate dalla " "classe :exc:`Exception`, direttamente o indirettamente." #: tutorial/errors.rst:356 msgid "" "Exception classes can be defined which do anything any other class can do, " "but are usually kept simple, often only offering a number of attributes that " "allow information about the error to be extracted by handlers for the " "exception." msgstr "" "Si possono definire classi di eccezione che fanno qualsiasi cosa possa fare " "qualsiasi altra classe, ma di solito vengono mantenute semplici, spesso " "offrendo solo un numero di attributi che consentono di estrarre informazioni " "sull'errore dai gestori per l'eccezione." #: tutorial/errors.rst:360 msgid "" "Most exceptions are defined with names that end in \"Error\", similar to the " "naming of the standard exceptions." msgstr "" "La maggior parte delle eccezioni è definita con nomi che terminano in " "\"Error\", simili alla denominazione delle eccezioni standard." #: tutorial/errors.rst:363 msgid "" "Many standard modules define their own exceptions to report errors that may " "occur in functions they define." msgstr "" "Molti moduli standard definiscono le proprie eccezioni per segnalare errori " "che possono verificarsi nelle funzioni che definiscono." #: tutorial/errors.rst:370 msgid "Defining Clean-up Actions" msgstr "Definizione di Azioni di Pulizia" #: tutorial/errors.rst:372 msgid "" "The :keyword:`try` statement has another optional clause which is intended " "to define clean-up actions that must be executed under all circumstances. " "For example::" msgstr "" "L'istruzione :keyword:`try` ha un'altra clausola opzionale che è intesa a " "definire azioni di pulizia che devono essere eseguite in tutte le " "circostanze. Per esempio::" #: tutorial/errors.rst:386 msgid "" "If a :keyword:`finally` clause is present, the :keyword:`!finally` clause " "will execute as the last task before the :keyword:`try` statement completes. " "The :keyword:`!finally` clause runs whether or not the :keyword:`!try` " "statement produces an exception. The following points discuss more complex " "cases when an exception occurs:" msgstr "" "Se è presente una clausola :keyword:`finally`, la clausola :keyword:`!" "finally` verrà eseguita come ultimo compito prima che l'istruzione :keyword:" "`try` completi. La clausola :keyword:`!finally` viene eseguita sia che " "l'istruzione :keyword:`!try` produca o meno un'eccezione. I seguenti punti " "discutono casi più complessi quando si verifica un'eccezione:" #: tutorial/errors.rst:392 msgid "" "If an exception occurs during execution of the :keyword:`!try` clause, the " "exception may be handled by an :keyword:`except` clause. If the exception is " "not handled by an :keyword:`!except` clause, the exception is re-raised " "after the :keyword:`!finally` clause has been executed." msgstr "" "Se si verifica un'eccezione durante l'esecuzione della clausola :keyword:`!" "try`, l'eccezione può essere gestita da una clausola :keyword:`except`. Se " "l'eccezione non è gestita da una clausola :keyword:`!except`, l'eccezione " "viene rilanciata dopo che la clausola :keyword:`!finally` è stata eseguita." #: tutorial/errors.rst:398 msgid "" "An exception could occur during execution of an :keyword:`!except` or :" "keyword:`!else` clause. Again, the exception is re-raised after the :keyword:" "`!finally` clause has been executed." msgstr "" "Un'eccezione potrebbe verificarsi durante l'esecuzione di una clausola :" "keyword:`!except` o :keyword:`!else`. Anche in questo caso, l'eccezione " "viene rilanciata dopo che la clausola :keyword:`!finally` è stata eseguita." #: tutorial/errors.rst:402 msgid "" "If the :keyword:`!finally` clause executes a :keyword:`break`, :keyword:" "`continue` or :keyword:`return` statement, exceptions are not re-raised." msgstr "" "Se la clausola :keyword:`!finally` esegue un'istruzione :keyword:`break`, :" "keyword:`continue` o :keyword:`return`, le eccezioni non vengono rilanciate." #: tutorial/errors.rst:406 msgid "" "If the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:" "`continue` or :keyword:`return` statement, the :keyword:`!finally` clause " "will execute just prior to the :keyword:`!break`, :keyword:`!continue` or :" "keyword:`!return` statement's execution." msgstr "" "Se l'istruzione :keyword:`!try` raggiunge un'istruzione :keyword:`break`, :" "keyword:`continue` o :keyword:`return`, la clausola :keyword:`!finally` " "verrà eseguita appena prima dell'esecuzione dell'istruzione :keyword:`!" "break`, :keyword:`!continue` o :keyword:`!return`." #: tutorial/errors.rst:412 msgid "" "If a :keyword:`!finally` clause includes a :keyword:`!return` statement, the " "returned value will be the one from the :keyword:`!finally` clause's :" "keyword:`!return` statement, not the value from the :keyword:`!try` " "clause's :keyword:`!return` statement." msgstr "" "Se una clausola :keyword:`!finally` include un'istruzione :keyword:`!" "return`, il valore restituito sarà quello dell'istruzione :keyword:`!return` " "della clausola :keyword:`!finally`, non il valore dell'istruzione :keyword:`!" "return` della clausola :keyword:`!try`." #: tutorial/errors.rst:418 msgid "For example::" msgstr "Per esempio::" #: tutorial/errors.rst:429 msgid "A more complicated example::" msgstr "Un esempio più complicato::" #: tutorial/errors.rst:454 msgid "" "As you can see, the :keyword:`finally` clause is executed in any event. " "The :exc:`TypeError` raised by dividing two strings is not handled by the :" "keyword:`except` clause and therefore re-raised after the :keyword:`!" "finally` clause has been executed." msgstr "" "Come puoi vedere, la clausola :keyword:`finally` viene eseguita in ogni " "caso. L'eccezione :exc:`TypeError` sollevata dividendo due stringhe non è " "gestita dalla clausola :keyword:`except` e quindi rilanciata dopo che la " "clausola :keyword:`!finally` è stata eseguita." #: tutorial/errors.rst:459 msgid "" "In real world applications, the :keyword:`finally` clause is useful for " "releasing external resources (such as files or network connections), " "regardless of whether the use of the resource was successful." msgstr "" "Nelle applicazioni del mondo reale, la clausola :keyword:`finally` è utile " "per rilasciare risorse esterne (come file o connessioni di rete), " "indipendentemente dal successo dell'uso delle risorse." #: tutorial/errors.rst:467 msgid "Predefined Clean-up Actions" msgstr "Azioni di Pulizia Predefinite" #: tutorial/errors.rst:469 msgid "" "Some objects define standard clean-up actions to be undertaken when the " "object is no longer needed, regardless of whether or not the operation using " "the object succeeded or failed. Look at the following example, which tries " "to open a file and print its contents to the screen. ::" msgstr "" "Alcuni oggetti definiscono azioni di pulizia standard da intraprendere " "quando l'oggetto non è più necessario, indipendentemente dal fatto che " "l'operazione che usa l'oggetto sia riuscita o fallita. Guarda il seguente " "esempio, che tenta di aprire un file e stampare il suo contenuto sullo " "schermo. ::" #: tutorial/errors.rst:477 msgid "" "The problem with this code is that it leaves the file open for an " "indeterminate amount of time after this part of the code has finished " "executing. This is not an issue in simple scripts, but can be a problem for " "larger applications. The :keyword:`with` statement allows objects like files " "to be used in a way that ensures they are always cleaned up promptly and " "correctly. ::" msgstr "" "Il problema con questo codice è che lascia il file aperto per un tempo " "indeterminato dopo che questa parte del codice ha terminato l'esecuzione. " "Questo non è un problema negli script semplici, ma può essere un problema " "per applicazioni più grandi. L'istruzione :keyword:`with` consente agli " "oggetti come i file di essere usati in modo tale da garantire che siano " "sempre puliti rapidamente e correttamente. ::" #: tutorial/errors.rst:487 msgid "" "After the statement is executed, the file *f* is always closed, even if a " "problem was encountered while processing the lines. Objects which, like " "files, provide predefined clean-up actions will indicate this in their " "documentation." msgstr "" "Dopo che l'istruzione è stata eseguita, il file *f* è sempre chiuso, anche " "se si è verificato un problema durante l'elaborazione delle linee. Gli " "oggetti che, come i file, forniscono azioni di pulizia predefinite " "indicheranno ciò nella loro documentazione." #: tutorial/errors.rst:495 msgid "Raising and Handling Multiple Unrelated Exceptions" msgstr "Sollevare e Gestire Eccezioni Multiple e Non Correlate" #: tutorial/errors.rst:497 msgid "" "There are situations where it is necessary to report several exceptions that " "have occurred. This is often the case in concurrency frameworks, when " "several tasks may have failed in parallel, but there are also other use " "cases where it is desirable to continue execution and collect multiple " "errors rather than raise the first exception." msgstr "" "Ci sono situazioni in cui è necessario segnalare diverse eccezioni che si " "sono verificate. Questo è spesso il caso nei framework di concorrenza, " "quando diversi compiti possono aver fallito in parallelo, ma ci sono anche " "altri casi d'uso in cui è desiderabile continuare l'esecuzione e raccogliere " "più errori piuttosto che sollevare la prima eccezione." #: tutorial/errors.rst:503 msgid "" "The builtin :exc:`ExceptionGroup` wraps a list of exception instances so " "that they can be raised together. It is an exception itself, so it can be " "caught like any other exception. ::" msgstr "" "L'eccezione built-in :exc:`ExceptionGroup` avvolge una lista di istanze di " "eccezione in modo tale che possano essere sollevate insieme. È un'eccezione " "a sé stante, quindi può essere catturata come qualsiasi altra eccezione. ::" #: tutorial/errors.rst:529 msgid "" "By using ``except*`` instead of ``except``, we can selectively handle only " "the exceptions in the group that match a certain type. In the following " "example, which shows a nested exception group, each ``except*`` clause " "extracts from the group exceptions of a certain type while letting all other " "exceptions propagate to other clauses and eventually to be reraised. ::" msgstr "" "Usando ``except*`` invece di ``except``, possiamo gestire selettivamente " "solo le eccezioni nel gruppo che corrispondono a un certo tipo. Nell'esempio " "seguente, che mostra un gruppo di eccezioni annidato, ogni clausola " "``except*`` estrae dal gruppo le eccezioni di un certo tipo lasciando che " "tutte le altre eccezioni si propaghino ad altre clausole e, infine, vengano " "rilanciate. ::" #: tutorial/errors.rst:572 msgid "" "Note that the exceptions nested in an exception group must be instances, not " "types. This is because in practice the exceptions would typically be ones " "that have already been raised and caught by the program, along the following " "pattern::" msgstr "" "Nota che le eccezioni annidate in un gruppo di eccezioni devono essere " "istanze, non tipi. Questo perché in pratica le eccezioni sarebbero " "tipicamente quelle che sono state già sollevate e catturate dal programma, " "seguendo il seguente pattern::" #: tutorial/errors.rst:592 msgid "Enriching Exceptions with Notes" msgstr "Arricchire le Eccezioni con Note" #: tutorial/errors.rst:594 msgid "" "When an exception is created in order to be raised, it is usually " "initialized with information that describes the error that has occurred. " "There are cases where it is useful to add information after the exception " "was caught. For this purpose, exceptions have a method ``add_note(note)`` " "that accepts a string and adds it to the exception's notes list. The " "standard traceback rendering includes all notes, in the order they were " "added, after the exception. ::" msgstr "" "Quando un'eccezione viene creata per essere sollevata, viene solitamente " "inizializzata con informazioni che descrivono l'errore verificatosi. Ci sono " "casi in cui è utile aggiungere informazioni dopo che l'eccezione è stata " "catturata. Per questo scopo, le eccezioni hanno un metodo ``add_note(note)`` " "che accetta una stringa e la aggiunge alla lista di note dell'eccezione. Il " "rendering standard del traceback include tutte le note, nell'ordine in cui " "sono state aggiunte, dopo l'eccezione. ::" #: tutorial/errors.rst:615 msgid "" "For example, when collecting exceptions into an exception group, we may want " "to add context information for the individual errors. In the following each " "exception in the group has a note indicating when this error has occurred. ::" msgstr "" "Per esempio, quando si raccolgono eccezioni in un gruppo di eccezioni, " "potremmo voler aggiungere informazioni di contesto per gli errori " "individuali. Nel seguente esempio, ogni eccezione nel gruppo ha una nota che " "indica quando si è verificato l'errore. ::"