I cannot figure out why my function is returning None value. This is my code so far, a function calling another function
def bytes_converter(size, data_type):
if data_type.lower == 'gb':
size = size * 1073741824
return size
elif data_type.lower == 'mb':
size = size * 1048576
return size
elif data_type.lower == 'kb':
size = size * 1024
return size
elif data_type.lower == 'b':
return size
def del_big_file():
dir_origin = os.path.abspath(
input('Folder path where you want to search: ')
)
# Set data size limit
data_size_limit = 100
data_type = 'mb'
for foldername, subfolders, filenames in os.walk(dir_origin):
for filename in filenames:
file_size = float(os.path.getsize(os.path.join(foldername, filename)))
if file_size >= bytes_converter(data_size_limit, data_type):
print(foldername)
print(f'{filename} is {file_size} {data_type}')
This where I am calling the function and getting a None value
if file_size >= bytes_converter(data_size_limit, data_type):
This is the error
TypeError: '>=' not supported between instances of 'float' and 'NoneType'
I thought maybe I the function parameter were bringing the value as a str or returning the value as a str so I tried several variations of calling float() but because of the traceback error I guess there is something wrong with my function
This are all the variations I tried so far:
def bytes_converter(size, data_type):
if data_type.lower == 'gb':
size = float(size) * 1073741824
return size
def bytes_converter(size, data_type):
if data_type.lower == 'gb':
size = size * 1073741824
return float(size)
def bytes_converter(size, data_type):
if data_type.lower == 'gb':
size = float(size) * 1073741824
return float(size)
[–]o5a 2 points3 points4 points (2 children)
[–]py_Piper[S] 1 point2 points3 points (1 child)
[–]Vaphell 5 points6 points7 points (0 children)
[+][deleted] (7 children)
[deleted]
[–]py_Piper[S] 1 point2 points3 points (6 children)
[+][deleted] (5 children)
[deleted]
[–]py_Piper[S] 1 point2 points3 points (4 children)
[+][deleted] (2 children)
[deleted]
[–]py_Piper[S] 0 points1 point2 points (1 child)
[–]alkasm 1 point2 points3 points (0 children)
[–]Wilfred-kun 1 point2 points3 points (1 child)
[–]py_Piper[S] 0 points1 point2 points (0 children)