1
在檢查MB
中的文件大小時,我收到了使用Python的語法錯誤。在檢查文件大小時出現語法錯誤
我得到if....statement
內的語法錯誤。
def createfile(request):
param = request.POST.get('param')
file_info = os.stat(param)
result = convert_bytes(file_info.st_size)
if result > 1 'MB' :
return render(request, 'plant/status.html',
{'message': "File size should be within 1 mb."})
def convert_bytes(num):
""" This function is used for measure file size """
for xe in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if num < 1024.0:
return "%3.1f %s" % (num, x)
num /= 1024.0
不知道你做了與否,但函數「convert_bytes」應該在函數「createfile」之前? –
嘗試:'如果結果>'1 MB':' - 雖然這個條件沒有多大意義 –
@MauriceMeyer有一個好點!試試看! –