access (o_excland nonblocking modes (o_nonblockwhen file is opened some of these flags are not portable across platforms (another reason to use built-in file objects most of the time)see the library manual or run dir(oscall on your machine for an exhaustive list of other open flags available one final note hereusing os open with the o_excl flag is the most portable way to lock files for concurrent updates or other process synchronization in python today we'll see contexts where this can matter in the next when we begin to explore multiprocessing tools programs running in parallel on server machinefor instancemay need to lock files before performing updatesif multiple threads or processes might attempt such updates at the same time wrapping descriptors in file objects we saw earlier how to go from file object to field descriptor with the fileno file object methodgiven descriptorwe can use os module tools for lower-level file access to the underlying file we can also go the other way--the os fdopen call wraps file descriptor in file object because conversions work both wayswe can generally use either tool set--file object or os modulefdfile os open( ' :\temp\spam txt'(os o_rdwr os o_binary)fdfile objfile os fdopen(fdfile'rb'objfile read( 'jello stdio file\ \nhello descriptor file\nin factwe can wrap file descriptor in either binary or text-mode file objectin text modereads and writes perform the unicode encodings and line-end translations we studied earlier and deal in str strings instead of bytesc:\pp \systempython import os fdfile os open( ' :\temp\spam txt'(os o_rdwr os o_binary)objfile os fdopen(fdfile' 'objfile read('jello stdio file\nhello descriptor file\nin python xthe built-in open call also accepts file descriptor instead of file name stringin this mode it works much like os fdopenbut gives you greater control--for exampleyou can use additional arguments to specify nondefault unicode encoding for text and suppress the default descriptor close reallythoughos fdopen accepts the same extra-control arguments in xbecause it has been redefined to do little but call back to the built-in open (see os py in the standard library) :\pp \systempython import os fdfile os open( ' :\temp\spam txt'(os o_rdwr os o_binary)fdfile file and directory tools