Python: 2.7.16

1
2
$ ll session1.1
-rw-r--r-- 1 webclown staff 66M 11 4 22:03 session1.1

方案1

1
2
3
4
5
6
7
8
9
10
$ python

Python 2.7.16 (default, Jun 5 2020, 22:59:21)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> f = open('session1.1', 'rb')
>>> f.seek(0, 2)
>>> f.tell()
68880526

方案2

os

1
2
3
4
5
6
7
8
9
10
11
$ python

Python 2.7.16 (default, Jun 5 2020, 22:59:21)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> f = open('session1.1', 'rb')
>>> import os
>>> os.fstat(f.fileno()).st_size
68880526
>>>
1
2
>>> os.path.getsize('session1.1')
68880526
1
2
>>> os.stat('session1.1').st_size
68880526