python - Closing a file descriptor I've used with fdopen -


what, if anything, then I need to close the file descriptor from os.open Is needed by I / code> and later is used with OSFodeDown ? OSError I get the code given below, I think the answer can be "nothing", but I do not get confirmation in the docs.

  fd = os As a file with Open (OS) path.expanduser ("~ / desktop / foo"), OS FDOPIN (FD, "WT"): Pass oscillos (FD) # OSER: [Eran 9] in Python 2 and usually On Python 3, the file is the owner of the  FDOPPIN  C standard IO file descriptor when the file closes with the  fclose , the underlying descriptor also stops. Is locked at the end of the  block with .  

Linux Manu The FDOPN () function combines a stream with the existing file descriptor, the mode of the FD stream ("R", "R +", "W", "W +") , "A", "A +") should be compatible with the mode of the file descriptor. The file stream of the new stream is related to the indicator FD, and the error and the end-of-file indicator has been cleared. Mode "W" or "w +" is not the reason for the transcription of the file. File D Skriptr not duped, and will be closed will be closed went stream created by fdopen (). is undefined result of implementing fdopen () for shared memory object.


Python 3 has a wrapper / approximation for the built-in function:

os.fdopen (fd, * args , ** kwargs)

Return an open file object associated with file descriptor fd . It is an alias of open () , the built-in function and accepts the same logic. The only difference is that the first argument of fdopen () should always be an integer.

and open are documentation documents to say on opening this file descriptor:

open (file, Mode = 'r', buffering = -1, encoding = none, errors = none, newline = none, closefd = true, openers = none)

Open file And return a related file object If the file can not be opened, an OSERR is raised.

File is either a string or byte object whose name gives the pathname of the file (relative to the absolute or current working directory) to open or an integer of the file (If a file descriptor is given to a file descriptor, it is turned off when the returned I / O object stops, until the closefd is not set to false.)

If you want to When the descriptor is opened, want to close the Python file object, then you

  fd = os.open (os.path.expanduser (OSFDOPEN (FD) "~ / Desktop / foo" as file with "WT", closefdie = folsey), OSO_Wornly): # I / O object has been separated, but FD is not valid osclose (fd) # error .  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -