Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.lang.python > #7617
| From | Max_Adamo <maxadamo@usenet.cnntp.org> |
|---|---|
| Newsgroups | it.comp.lang.python |
| Subject | Re: Range ciclo for |
| Date | 2016-03-09 21:45 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <nbq5i4$d4t$1@dont-email.me> (permalink) |
| References | <AkYAy.41793$pt.7627@tornado.fastwebnet.it> <nbnj88$j2t$4@dont-email.me> <nbpuii$ktb$1@adenine.netfront.net> |
Il Wed, 09 Mar 2016 20:46:25 +0100, Nando ha scritto:
> Il 08/03/2016 23:20, Max_Adamo ha scritto:
>> Il Mon, 29 Feb 2016 15:11:45 +0100, Smith ha scritto:
>>
>>> Ciao a tutti,
>>> vorrei numerare il numero di file all'interno di una directory con
>>> python:
>>>
>>>
>> è sempre bello avere più soluzioni:
>>
>> for i in enumerate(os.listdir("/home"), 1):
>> print "{0} {1}".format(i[0], i[1])
>>
>> non devi fare nemmeno l'import.
>>
>>
> Ho provato la tua soluzione, ma non funziona se non importo os o listdir
> da os. Stranamente, l'help trova os.listdir anche se non importata ma
> poi python non me la lascia usare.
azz... certo, hai ragione tu :) Se c'è os.listdir, devi importare os.
Al limite, per risparmiare non so cosa, si può fare così:
from os import listdir
for i in enumerate(listdir("/home"), 1):
print "{0} {1}".format(i[0], i[1])
p.s.: nota il format, che spesso è più conveniente della concatenazione,
in quando se ne frega di stringhe, int e ti evita errori grossolani.
--
Massimiliano Adamo
Back to it.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Range ciclo for Smith <smith@a-team.it> - 2016-02-29 15:11 +0100
Re: Range ciclo for Antonio 6sette <hindemit@tiscali.it> - 2016-02-29 16:56 +0000
Re: Range ciclo for Enrico Bianchi <enrico.bianchi@ymail.com> - 2016-02-29 17:11 +0000
Re: Range ciclo for Smith <smith@a-team.it> - 2016-03-01 09:18 +0100
Re: Range ciclo for Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-03-08 22:20 +0000
Re: Range ciclo for Nando <nan@nan.nan> - 2016-03-09 20:46 +0100
Re: Range ciclo for Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-03-09 21:45 +0000
Re: Range ciclo for boffi <boffi@debian.i-did-not-set--mail-host-address--so-tickle-me> - 2016-03-16 22:46 +0100
Re: Range ciclo for Enrico Bianchi <enrico.bianchi@ymail.com> - 2016-03-24 23:14 +0000
Re: Range ciclo for Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-03-26 09:10 +0000
Re: Range ciclo for Enrico Bianchi <enrico.bianchi@ymail.com> - 2016-03-26 13:55 +0000
Re: Range ciclo for Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-03-26 17:09 +0000
Re: Range ciclo for Enrico Bianchi <enrico.bianchi@ymail.com> - 2016-03-29 22:21 +0000
Re: Range ciclo for Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-04-02 06:48 +0000
Re: Range ciclo for Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-04-02 06:59 +0000
Re: Range ciclo for atm <atm@fartwebnet.it> - 2016-04-10 13:12 +0000
Re: Range ciclo for Termoregolato <waste@is.invalid> - 2016-04-12 20:11 +0200
Re: Range ciclo for atm <atm@fartwebnet.it> - 2016-04-19 19:17 +0000
Re: Range ciclo for Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-04-23 15:33 +0000
Re: Range ciclo for atm <atm@fartwebnet.it> - 2016-05-01 17:07 +0000
Re: Range ciclo for Max_Adamo <maxadamo@usenet.cnntp.org> - 2016-05-01 17:57 +0000
Re: Range ciclo for Andrea D'Amore <anddam+NOSPAM@brapi.net> - 2016-05-06 14:40 +0200
Re: Range ciclo for atm <atm@fartwebnet.it> - 2016-05-17 18:33 +0000
Re: Range ciclo for pecore@pascolo.org - 2016-04-19 00:54 +0200
Re: Range ciclo for Andrea D'Amore <anddam+NOSPAM@brapi.net> - 2016-05-06 14:42 +0200
csiph-web