[Python] consigli su: os.path.getsize

Daniel Pyrathon pirosb3 a gmail.com
Dom 26 Giu 2011 11:18:38 CEST


ecco a lei ;)

>>> for x in os.listdir('.'):
...     if x is not '.' or x is not '..':
...             print x

Questo, per stampare le directory in wd.
Come puoi notare, scrivere Python è una bellezza, anche mamma saprebbe dirmi
cosa fa " if x is not '.' or x is not '..' " ;)

Un saluto
Chiedi se hai altre domande!
Dan

Il giorno 26 giugno 2011 10:38, Freeze NorthPole <freeze782 at gmail.com> ha
scritto:

> ciao,
> e come faccio ad escludere le due directory?
> Grazie Mille
>
> ps. cmq con il consiglio di Marco ho risolto con l'errore :)
>
> 2011/6/26 Daniel Pyrathon <pirosb3 at gmail.com>:
> > quando elenchi i file, miraccomando escludi '..' e '.' che si riferiscono
> > alla directory precedente e a quella stessa ;)
> > Se escludi questi non penso dovresti avere OSError.
> > Facci sapere
> > Dan
> >
> > Il giorno 26 giugno 2011 05:26, Marco Mariani <birbag at gmail.com> ha
> scritto:
> >>
> >> try:
> >>     dim = os.path.getsize(list[i])
> >> except OSError:
> >>     dim = 0
> >>
> >>
> >> Nota che WindowsError eredita da OSError, usando except con
> quest'ultimo,
> >> catturi entrambi i casi.
> >>
> >> E cambia nome alla variabile 'list', non si riassegnano i nomi degli
> >> oggetti builtin se non ci sono ottimi motivi.
> >>
> >>
> >>
> >> _______________________________________________
> >> Python mailing list
> >> Python at lists.python.it
> >> http://lists.python.it/mailman/listinfo/python
> >>
> >
> >
> >
> > --
> > *************
> > PirosB3
> > http://pirosb3.com
> >
> > _______________________________________________
> > Python mailing list
> > Python at lists.python.it
> > http://lists.python.it/mailman/listinfo/python
> >
> >
> _______________________________________________
> Python mailing list
> Python at lists.python.it
> http://lists.python.it/mailman/listinfo/python
>



-- 
*************

PirosB3

http://pirosb3.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.python.it/pipermail/python/attachments/20110626/ba17bbd0/attachment-0001.html>


Maggiori informazioni sulla lista Python