Skip to content

Instantly share code, notes, and snippets.

@alejolp
Created April 11, 2014 09:52
Show Gist options
  • Save alejolp/10454635 to your computer and use it in GitHub Desktop.
Save alejolp/10454635 to your computer and use it in GitHub Desktop.
$ uname -a
Linux computer 2.6.32-431.5.1.el6.i686 #1 SMP Wed Feb 12 09:07:48 CET 2014 i686 i686 i386 GNU/Linux
$ python
Python 2.6.6 (r266:84292, Jan 23 2014, 10:37:44)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ python pyseektest.py
f.read '0'
file tell 1
os tell 1
os.read '1'
file tell 1
os tell 2
f.read '2'
file tell 2
os tell 3
os.read '3'
file tell 2
os tell 4
#/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def main():
with open('test.txt', 'wb') as f:
f.write("01234567890")
f = open('test.txt', 'rb', 0)
print "f.read", repr(f.read(1))
print "file tell", f.tell()
print "os tell", os.lseek(f.fileno(), 0, os.SEEK_CUR)
print
print "os.read", repr(os.read(f.fileno(), 1))
print "file tell", f.tell()
print "os tell", os.lseek(f.fileno(), 0, os.SEEK_CUR)
print
print "f.read", repr(f.read(1))
print "file tell", f.tell()
print "os tell", os.lseek(f.fileno(), 0, os.SEEK_CUR)
print
print "os.read", repr(os.read(f.fileno(), 1))
print "file tell", f.tell()
print "os tell", os.lseek(f.fileno(), 0, os.SEEK_CUR)
print
f.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment