Added .py file for support functions
This commit is contained in:
parent
8a10fba79f
commit
fc3ddd47d4
11
extras.py
Normal file
11
extras.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
def get_size(file_path, unit='bytes'):
|
||||||
|
file_size = os.path.getsize(file_path)
|
||||||
|
exponents_map = {'bytes': 0, 'kb': 1, 'mb': 2, 'gb': 3}
|
||||||
|
if unit not in exponents_map:
|
||||||
|
raise ValueError("Must select from \
|
||||||
|
['bytes', 'kb', 'mb', 'gb']")
|
||||||
|
else:
|
||||||
|
size = file_size / 1024 ** exponents_map[unit]
|
||||||
|
return round(size, 1)
|
Loading…
Reference in New Issue
Block a user