Zanurkuj w Pythonie/Wyjątki i operacje na plikach - wszystko razem: Różnice pomiędzy wersjami

Usunięta treść Dodana treść
Sasek (dyskusja | edycje)
m poprawa nawigacji
Piotr (dyskusja | edycje)
tłumaczenie
Linia 2:
== Wszystko razem ==
 
Jeszcze raz ułożymy wszystkie klocki domina w jednym miejscu. Już wcześniej poznaliśmy, w jaki sposób działa każda linia kodu. Teraz znowu do tego powrócimy i zobaczymy, jak to wszystko jest ze sobą dopasowane.
Once again, all the dominoes are in place. You've seen how each line of code works. Now let's step back and see how it all fits together.
 
'''Przykład 6.21. listDirectory'''
Linia 20:
return [getFileInfoClass(f)(f) for f in fileList] #(6)
 
# <tt>listDirectory</tt> isjest thegłówną mainatrakcją attractiontego of this entire modulemodułu. ItBierze takes aona <tt>directory</tt> (likenp. <tt class="lang-none">c:\music\_singles\</tt>) ini mylistuje case)wszystkie andpliki ao listinteresujących ofnas interestingrozszeżeniach file(jak extensionsna (likeprzykład <tt>['.mp3']</tt>), anda itnastępnie returnszwraca alistę listinstancji ofklas, classktóre instancesdziałają thatpodobnie actjak likesłowniki, dictionariesa thatprzechowują containone metadatametadane aboutna eachtemat interestingkażdego filepliku inw thattym directorykatalogu. AndI itto doeswszystko itjest inwykonywane just aza fewpomocą straightforwardkilku linesprostych oflinii codekodu.
# As you saw in the previous section, this line of code gets a list of the full pathnames of all the files in directory that have an interesting file extension (as specified by fileExtList).
# Old-school Pascal programmers may be familiar with them, but most people give me a blank stare when I tell them that Python supports nested functions -- literally, a function within a function. The nested function getFileInfoClass can be called only from the function in which it is defined, listDirectory. As with any other function, you don't need an interface declaration or anything fancy; just define the function and code it.