Python Forum
Print Function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Print Function (/thread-12973.html)



Print Function - Prasanna - Sep-21-2018

HI Friends,

I want to know how "PRINT()" function is working in back end.


RE: Print Function - snippsat - Sep-21-2018

Mouse over VS Code.
[Image: 1SRz4P.jpg]
See parameter that print() function has.
>>> n = 9
>>> print("n=", n, sep='00000', end='\n\n')
n=000009

>>> 
Documentation for print() function.
print() function is implemented in C,source code is here.


RE: Print Function - Prasanna - Sep-25-2018

thank you snippsat


RE: Print Function - nzcan - Oct-06-2018

answered


RE: Print Function - volcano63 - Oct-06-2018

(Oct-06-2018, 08:54 AM)nzcan Wrote: hi,
i am curious how the 'file' argument of print() could be used.
i am trying:
....
>>> print('hello, world!', file=d) [/python]
but i am receiving the following error:
>>> print('hello, world!', file=d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
io.UnsupportedOperation: not writable 
as it is written in the documentation about 'print()' build-in function ' ... The file argument must be an object with a write(string) method; ... '
then ... why the 'd'-object should not be writable when it has the 'write' method?

It could - if you open a file in a write mode. File objects are subset of stream objects - most of which have write method - but file requires to be opened with write permission to allow writing operation
Output:
In [10]: with open('Groups.ipynb') as f: ...: print(f.writable()) ...: False In [11]: with open('Groups.ipynb', 'w') as f: ...: print(f.writable()) ...: True
In-memory text streams are writable by default
Output:
In [12]: io.StringIO().writable() Out[12]: True