Path: csiph.com!news.mixmin.net!aioe.org!bofh.it!tornado.fastwebnet.it!53ab2750!not-for-mail Subject: Re: Listdir References: Newsgroups: it.comp.lang.python From: Smith Message-ID: <7fb1bf12-0044-b6a8-a0fc-3d422f851ee7@smith.it> User-Agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Lines: 30 Date: Mon, 5 Sep 2016 18:39:32 +0200 NNTP-Posting-Host: 93.41.25.206 X-Complaints-To: newsmaster@fastweb.it X-Trace: tornado.fastwebnet.it 1473093572 93.41.25.206 (Mon, 05 Sep 2016 18:39:32 CEST) NNTP-Posting-Date: Mon, 05 Sep 2016 18:39:32 CEST Xref: csiph.com it.comp.lang.python:7684 On 05/09/2016 17:58, Claudio_F wrote: > Il 05/09/2016 17:25, Smith ha scritto: >> Ciao a tutti, >> volevo sapere perchè nonostante i file siano presenti sulla directory >> che scrivo in input mi restituisce file not found. >> Mi potete aiutare? >> Grazie >> >> >> a = input("Digita la directory dove vuoi trovare i file py: ") >> for file in os.listdir(a): >> if file.endswith(".py"): >> print(file) >> else: >> break >> print("File not found") > > > break non serve a niente (almeno nel codice postato), non c'e` un ciclo > while o for da interrompere. > > La funzione print alla fine (sempre nel codice postato) viene eseguita > sempre e comunque (non e` subordinata ad alcuna condizione). > > La controdomanda e`: oltre al messaggio "File not found" che (nel codice > postato) viene stampato sempre e comunque, viene anche scritto qualche > nome di file .py o niente? > > Non viene stampato nessun file .py , nonostante siano presenti