Low-Level File I/O

os.open(file [,flags [,mode]])

  • Opens a file and returns an integer file descriptor
  • flags is the bitwise-or of the following
     O_RDONLY             Open file for reading
     O_WRONLY             Open file for writing
     O_RDWR               Open file for read/write
     O_APPEND             Append to the end of the file
     O_CREAT              Create file if it doesn't exit
     O_NONBLOCK           Don't block on open,read, or write.
     O_TRUNC              Truncate to zero length
     O_TEXT               Text mode (Windows)
     O_BINARY             Binary mode (Windows)
  • mode is file access mode according to standard Unix conventions

Example

     import os
     f = os.open("foo", O_WRONLY | O_CREAT, 0644) 
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 39
July 17, 2000, beazley@cs.uchicago.edu
>>>