I'd like to remove files which is empty.
import os
book_list = ['Automate the Boring Stuff with Python.pdf',
'OReilly.Think.Python.2nd.Edition.2015.12.pdf',
'Apress-Magnus_Lie_Hetland-python_algorithms.pdf',
'Python for Data Analysis - 2012.pdf']
for book in book_list:
if os.path.getsize(book) == 0:
os.remove(book)
It seems not pythonic because of the boolean comparsion ==
.
How to accomplish such a task in an alternative way?
That is correct usage of the equality operator. If you want to be 'fancy' you can use the code provided by sam-pyt:
if not os.path.getsize(book)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With