2017年7月14日 星期五

[ Python 常見問題 ] How to check file size in python?

Source From Here 
Question 
I want to do something based on the file size. For example, if the size is greater than 0, I will send an email to somebody, otherwise continue to other things. How do I check the file size? 

How-To 
Use os.stat, and use the st_size (Size in bytes of a plain file; amount of data waiting on some special files.) member of the resulting object: 
>>> import os 
>>> statinfo = os.stat('somefile.txt') 
>>> statinfo 
(33188, 422511L, 769L, 1, 1032, 100, 926L, 1105022698,1105022732, 1105022732) 
>>> statinfo.st_size 
926L


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...