Python--os (ii) File object

Source: Internet
Author: User

This section describes the functions of the OS module to create a file object

Os.fdopen (fd[, mode[, bufsize])

opens the file with a file descriptor, returns an open file object connected to the FD , the parameter mode and bufsize have the same meaning as the corresponding parameter of the Python built-in function open (), if Fdopen () throws an exception, and the file for FD is in an not closed state.

  Applies To: Unix, Windows.

  Changed in version 2.3: If parameter mode is specified, then the parameter must start with either ' R ',' W ' or ' a ', or throw an exception ValueError

Changed in version 2.5: On Unix, if the parameter Mode in ' A ' begins, it is set on the file description word O_append flag.

Os.tmpfile ()

Returns a new temporary file object in update mode (W+B), which has no path entry and is automatically deleted once the file description word is lost.

Applies To: Unix, Windows.

  
Deprecation statement
All of the following functions are obsolete, using the subprocess module!
  
Os.popen (command[, mode[, bufsize])    
  
Opens a pipe that connects to the (from/To) parameter command , returns an open file object that is connected to the pipeline, and the read-write property of the pipeline is specified by the parameter mode -- ' R ' (default) or ' W ' 。
The parameter bufsize is the same as the corresponding parameter of the built-in function open (), and the exit state of the parameter command (encoded in the format specified in wait () ) can be used as the cl The return value of the >ose () method, except for the return status of 0 (normal exit), at which time none is returned.
Applies To: Unix, Windows.
  
Here are some obsolete popen* () functions used to create child processes and execute commands
  
The parameter bufsize of the following three functions indicates the I/O buffer size of the pipe, and the parameter mode should be ' B ' or ' t ', which is required on Windows option to determine whether the file object is opened in byte or text format, and the default is ' t '. on Unix, parameter cmd may be a sequence, which means that parameters are passed directly to the program without the need for Shell intervention (same as OS.SPAWNV ()). If the parameter cmd is a string, it is passed to the shell (same as Os.system ()).
None of these methods can get the exit status of a child process, and the Subprocess module is required to control input, output, and get return values at the same time .
For a deadlock that may be caused by using these functions, see Flow Control issues.
  
os.popen2 (cmd[, mode[, bufsize])
  
Executes cmd as a child process, returning a file object (Child_stdin, child_stdout).
  Applies To: Unix, Windows.
  
Os.popen3 (cmd[, mode[, bufsize])
  
executes as a child process cmd , returns the file object (Child_stdin, child_stdout, child_stderr)
  Applies To: Unix, Windows.
  
Os.popen4 (cmd[, mode[, bufsize])
  
Executes cmd as a child process, returning a file object (Child_stdin, child_stdout_and_stderr) .
  Applies To: Unix, Windows.
Note
   Child_stdin,child_stdout, and child_stderr are named from the perspective of the child process, so they are the standard input, standard output, and standard error for the child process, respectively.
  
Deprecation statement   
The last four functions are obsolete, using the subprocess module. Read more about replacing older Functions with the subprocess Module section.

Python--os (ii) File object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.