Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.python > #7685

Re: Listdir

Path csiph.com!news.mixmin.net!aioe.org!.POSTED!not-for-mail
From Claudio_F <clau.fin@tin.it>
Newsgroups it.comp.lang.python
Subject Re: Listdir
Date Mon, 5 Sep 2016 18:50:28 +0200
Organization Aioe.org NNTP Server
Lines 42
Message-ID <nqk7oi$1lhh$1@gioia.aioe.org> (permalink)
References <t7gzz.96$qi6.69@tornado.fastwebnet.it> <nqk4m7$1gi3$1@gioia.aioe.org> <7fb1bf12-0044-b6a8-a0fc-3d422f851ee7@smith.it>
NNTP-Posting-Host xieranVEqL2Q1m6dtfOiNw.user.gioia.aioe.org
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Complaints-To abuse@aioe.org
User-Agent Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
X-Notice Filtered by postfilter v. 0.8.2
Xref csiph.com it.comp.lang.python:7685

Show key headers only | View raw


Il 05/09/2016 18:39, Smith ha scritto:
> 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


Prima ho sbagliato io sorry... il for c'e`, quindi al primo break il for 
termina.

Se il primo file trovato *non* e` un .py il for termina subito e non 
stampa gli altri.

Il problema e` quel break. Il ciclo non va mai interrotto.

Back to it.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Listdir Smith <smith@smith.com> - 2016-09-05 17:25 +0200
  Re: Listdir Claudio_F <clau.fin@tin.it> - 2016-09-05 17:58 +0200
    Re: Listdir Smith <smith@smith.it> - 2016-09-05 18:39 +0200
      Re: Listdir Claudio_F <clau.fin@tin.it> - 2016-09-05 18:50 +0200
    Re: Listdir Enrico Bianchi <enrico.bianchi@ymail.com> - 2016-09-24 17:30 +0000

csiph-web