Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print Function
#1
HI Friends,

I want to know how "PRINT()" function is working in back end.
Reply
#2
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.
Reply
#3
thank you snippsat
Reply
#4
answered
Reply
#5
(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
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 290 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  How to print variables in function? samuelbachorik 3 902 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  How to print the output of a defined function bshoushtarian 4 1,281 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  Why does absence of print command outputs quotes in function? Mark17 2 1,377 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  return vs. print in nested function example Mark17 4 1,739 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  output correction using print() function afefDXCTN 3 11,076 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  print function output wrong with strings. mposwal 5 3,111 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Output with none, print(x) in function Vidar567 3 2,506 Nov-24-2020, 05:40 PM
Last Post: deanhystad
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,475 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  Invalid syntax on print function DoctorSmiles 2 2,810 Jul-12-2020, 07:39 PM
Last Post: DoctorSmiles

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020