Python os.stat(file_name).st_size versus os.path.getsize(file_name)

后端 未结 1 1180
野性不改
野性不改 2020-12-31 08:20

I\'ve got two pieces of code that are both meant to do the same thing -- sit in a loop until a file is done being written to. They are both mainly used for files coming in

相关标签:
1条回答
  • 2020-12-31 09:08

    In CPython 2.6 and 2.7, os.path.getsize() is implemented as follows:

    def getsize(filename):
        """Return the size of a file, reported by os.stat()."""
        return os.stat(filename).st_size
    

    From this, it seems pretty clear that there is no reason to expect the two approaches to behave differently (except perhaps due to the different structures of the loops in your code).

    0 讨论(0)
提交回复
热议问题