I've searched and I can only find questions about the other way around: writing stdin to a file.
Is there a quick and easy way to dump the contents of a file to stdout
?
In Python, whenever we use print() the text is written to Python's sys. stdout, whenever input() is used, it comes from sys. stdin, and whenever exceptions occur it is written to sys. stderr.
So print() also a function with the return value with None . So the return value of python function is None . But you can call the function(with parenthesis ()) and save the return value in this way. So the var variable has the return value of some_function() or the default value None .
Sure. Assuming you have a string with the file's name called fname
, the following does the trick.
with open(fname, 'r') as fin: print(fin.read())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With