Re: A technique from a chatbot

Liste des GroupesRevenir à cl python 
Sujet : Re: A technique from a chatbot
De : pieter-l (at) *nospam* vanoostrum.org (Pieter van Oostrum)
Groupes : comp.lang.python
Date : 03. Apr 2024, 22:15:18
Autres entêtes
Message-ID : <m2le5up2qh.fsf@cochabamba-1.kpn>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin)
ram@zedat.fu-berlin.de (Stefan Ram) writes:

  It can lead to errors:
>
def first_word_beginning_with_e( list_ ):
    for word in list_:
        if word[ 0 ]== 'e': return word
    something_to_be_done_at_the_end_of_this_function()
   
  The call sometimes will not be executed here!
  So, "return" is similar to "break" in that regard.

That can be solved with finally:

def first_word_beginning_with_e( list_ ):
    try:
        for word in list_:
            if word[ 0 ]== 'e': return word
    finally:
        print("something_to_be_done_at_the_end_of_this_function()")

--
Pieter van Oostrum <pieter@vanoostrum.org>
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]

Date Sujet#  Auteur
2 Apr 24 * A technique from a chatbot15Stefan Ram
2 Apr 24 +* Re: A technique from a chatbot12Piergiorgio Sartor
2 Apr 24 i+* Re: A technique from a chatbot8Thomas Passin
4 Apr 24 ii`* Re: A technique from a chatbot7Mark Bourne
4 Apr 24 ii +* Re: A technique from a chatbot2<avi.e.gross
5 Apr 24 ii i`- Re: A technique from a chatbot1Mark Bourne
4 Apr 24 ii +- Re: A technique from a chatbot1Thomas Passin
5 Apr 24 ii `* Re: A technique from a chatbot3Stefan Ram
5 Apr 24 ii  +- Re: A technique from a chatbot1Stefan Ram
5 Apr 24 ii  `- Re: A technique from a chatbot1Mark Bourne
3 Apr 24 i+- Re: A technique from a chatbot1<avi.e.gross
3 Apr 24 i+- Re: A technique from a chatbot1Thomas Passin
3 Apr 24 i`- Re: A technique from a chatbot1<avi.e.gross
3 Apr 24 +- Re: A technique from a chatbot1Pieter van Oostrum
3 Apr 24 `- Re: A technique from a chatbot1Michael F. Stemper

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal