As and addition to what @wavic say,there are bad stuff in this code.
Never use
Also overwrite of the original filepaths,you are getting back
So look at this:
Never use
range(len(something)
,not gone give up on this Also overwrite of the original filepaths,you are getting back
byte size
so do not call it filepaths.So look at this:
# Bad import os filepaths = ['E:/1py_div/uni.txt', 'E:/1py_div/h.py', 'E:/1py_div/cloud9.txt'] for i in range(len(filepaths)): filepaths[i] = os.path.getsize(filepaths[i]) print(filepaths) # [22, 190, 42043]
# Good import os filepaths = ['E:/1py_div/uni.txt', 'E:/1py_div/h.py', 'E:/1py_div/cloud9.txt'] file_byte_size = [] for index,item in enumerate(filepaths): file_byte_size.append(os.path.getsize(item)) print(file_byte_size) #[22, 190, 42043]Ahh come to think of this,it's easy to forget the the easiest solution.
# Best import os filepaths = ['E:/1py_div/uni.txt', 'E:/1py_div/h.py', 'E:/1py_div/cloud9.txt'] file_byte_size = [] for item in filepaths: file_byte_size.append(os.path.getsize(item)) print(file_byte_size) #[22, 190, 42043]list comprehension is also okay.
import os filepaths = ['E:/1py_div/uni.txt', 'E:/1py_div/h.py', 'E:/1py_div/cloud9.txt'] file_byte_size = [os.path.getsize(item) for item in filepaths] #[22, 190, 42043]