Author Dusty Phillips Reviewers



Download 2,95 Mb.
Pdf ko'rish
bet137/183
Sana20.07.2022
Hajmi2,95 Mb.
#831085
1   ...   133   134   135   136   137   138   139   140   ...   183
Bog'liq
python3-oop

[
 140 
]
with filename.open("w") as file:
file.write(contents)
def zip_files(self):
with zipfile.ZipFile(self.filename, 'w') as file:
for filename in self.temp_directory.iterdir():
file.write(str(filename), filename.name)
shutil.rmtree(str(self.temp_directory))
if __name__ == "__main__":
ZipReplace(*sys.argv[1:4]).zip_find_replace()
For brevity, the 
code for zipping and unzipping files is sparsely documented. Our 
current focus is on object-oriented design; if you are interested in the inner details of 
the 
zipfile
module, refer to the documentation in the standard library, either online 
or by typing 
import zipfile ; help(zipfile)
into your interactive interpreter. 
Note that this example only searches the top-level files in a ZIP file; if there are any 
folders in the unzipped content, they will not be scanned, nor will any files inside 
those folders.
The last two lines in the example allow us to run the program from the command 
line by passing the 
zip
filename, search string, and replace string as arguments:
python zipsearch.py hello.zip hello hi
Of course, this object does not have to be created from the command line; it could be 
imported from another module (to perform batch ZIP file processing) or accessed as 
part of a GUI interface or even a higher-level management object that knows where 
to get ZIP files (for example, to retrieve them from an FTP server or back them up to 
an external disk).
As programs become more and more complex, the objects being modeled become less 
and less like physical objects. Properties are other abstract objects and methods are 
actions that change the state of those abstract objects. But at the heart of every object, 
no matter how complex, is a set of concrete properties and well-defined behaviors.

Download 2,95 Mb.

Do'stlaringiz bilan baham:
1   ...   133   134   135   136   137   138   139   140   ...   183




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish