Thread: Frustrated

Page 2 of 2 First 12
  • Jump to page:
  1. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    San Francisco Bay
    Rep Power
    Originally Posted by boragora
    I was always under the impression that square brackets meant optional, and in the above case it seems like mode='r' is already set as default. Why would boogers code produce an error asking for a string as the second argument ('r' according to b49P23TIvg's response) if the string is optional?
    From the manual:
    os.popen(command[, mode[, bufsize]])

    Open a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. The bufsize argument has the same meaning as the corresponding argument to the built-in open() function. The exit status of the command (encoded in the format specified for wait()) is available as the return value of the close() method of the file object, except that when the exit status is zero (termination without errors), None is returned.
    Yes, the mode argument is optional, defaulting to 'r'. Obviously, if you do choose to supply the optional argument, it has to have an appropriate value: as the description states, it needs to be 'r' or 'w', allowing you respectively to read from or write to the subprocess. The fact that the mode is not a required argument doesn't allow you to give it a nonsense value, like "sys.stdout" or

    While we're here, the manual goes on to say:
    Deprecated since version 2.6: This function is obsolete. Use the subprocess module.
    There's nothing os.popen does that subprocess.Popen doesn't do better. For example, with subprocess.Popen, you can access all three standard I/O streams of the process (stdin, stdout, and stderr) if you want. os.popen is basically just a work-alike for the C standard library function of the same name, while the subprocess module is designed specifically for Python.
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Rep Power
    As to nonsensical values: hence the reason I later referred to it as a brain cramp.
    Certainly not something worth biting someone's head off for...
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo