#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    12

    difference between the two


    Is there any difference between print and sys.stderr.write


    PHP Code:
    >>> sys.stderr.write("Test")
    Test
    >>> print "Test"
    Test 

    Subha
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Location
    Cape Town, South Africa
    Posts
    131
    Rep Power
    12
    Ya.

    (I think you meant sys.stdout.write() though...)

    sys.stderr.write('...'):

    - sends output to the stderr pipe in unix

    sys.stdout.write('...'):

    - sends output to the stdout pipe in unix

    In windows systems, these both go to the current interacive window.

    The print function basically adds a newline character to your string and calls sys.stdout.write() - so its basically a wrapper for it (with the difference being the \n).

    Later,
    K
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Since print (by default) ultimately calls sys.stdout.write you can change where printing goes by re-assigning sys.stdout to some other object with file like features (e.g a write method).

    Now with the newer Pythons of course there is the output modifier:
    print[>> fileobject,] [s1 [, s2 ]* [,] Writes to sys.stdout, or to fileobject if supplied. Puts spaces between arguments. Puts newline at end unless statement ends with comma.
    grim

IMN logo majestic logo threadwatch logo seochat tools logo