Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is stdio.write in python?

Tags:

python

I looked everywhere but I didn't find anything about it. In my school, We use stdio.write or stdio.writeln instead of print. Is there a difference betweeen them? and I don't understand that functions' purpose. Are there anyone to explain to me very clearly?

Thank you so much for replying.

edit: i asked this question nearly 2 years ago and i wanna explain what is this to guys who students. stdio.write means like normal print. if you write in java, you use like this code; System.out.print actually every program has different style.

but why there is nothing about stdio.write on internet? it is because for book which taken course books. it is from special library. nothing important. just know it. it is just print. and after the finish this course you wont use this library again. it is just for understanding the logic of coding.

like image 838
bkk Avatar asked Aug 30 '26 07:08

bkk


1 Answers

If you're talking about this library (which isn't a standard library, just something someone wrote), it looks like mostly a bunch of convenience functions for reading different datatypes from stdin.

As far as the difference between stdio.write and print, stdio.write looks to be a shim that works in both python 2 and 3 that will encode whatever unicode or byte string you have to utf-8 before it tries to write it, potentially to prevent encoding errors for some consoles that will try to encode out to ascii and fail.

def write(x=''):
    """
    Write x to standard output.
    """
    if (sys.hexversion < 0x03000000):
        x = unicode(x)
        x = x.encode('utf-8')
    else:
        x = str(x)
    sys.stdout.write(x)
    sys.stdout.flush()
like image 97
Brendan Abel Avatar answered Aug 31 '26 21:08

Brendan Abel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!