Python Forum
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get print() output
#17
the function is written under normal filesystem assumptions it can be given a file name and will open it or be given an already open file object.  in both cases it closes it when done writing.  i have been giving it a filesystem file and when the function returns, open the file for reading and reading it.

i think what it does is:

def function(...,file=None):
    try:
        o=open(file.fileno(),'w')
    except whatever:
        try:
            o=open(file,'w')
        except whatever:
            o=sys.stdout
    ...
    print(stuff.file=o) # many places
    ...
    o.close()
    return
or something similar like holding options in a dictionary.

it's a rather normal thing to close a file when done with it.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
get print() output - by Skaperen - Apr-24-2017, 06:26 AM
RE: get print() output - by Mekire - Apr-24-2017, 06:40 AM
RE: get print() output - by Skaperen - Apr-24-2017, 09:56 AM
RE: get print() output - by wavic - Apr-24-2017, 06:57 AM
RE: get print() output - by Mekire - Apr-24-2017, 07:03 AM
RE: get print() output - by wavic - Apr-24-2017, 07:13 AM
RE: get print() output - by Mekire - Apr-24-2017, 07:20 AM
RE: get print() output - by wavic - Apr-24-2017, 10:10 AM
RE: get print() output - by Skaperen - Apr-25-2017, 06:16 AM
RE: get print() output - by wavic - Apr-25-2017, 06:58 AM
RE: get print() output - by Skaperen - Apr-25-2017, 07:00 AM
RE: get print() output - by wavic - Apr-25-2017, 07:38 AM
RE: get print() output - by Skaperen - Apr-25-2017, 09:58 AM
RE: get print() output - by wavic - Apr-25-2017, 11:19 AM
RE: get print() output - by Skaperen - Apr-26-2017, 01:18 AM
RE: get print() output - by wavic - Apr-26-2017, 06:10 AM
RE: get print() output - by Skaperen - Apr-26-2017, 07:33 AM
RE: get print() output - by wavic - Apr-26-2017, 08:04 AM
RE: get print() output - by Skaperen - Apr-27-2017, 01:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,342 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  How to output one value per request of the CSV and print it in another func? Student44 3 1,536 Nov-11-2022, 10:45 PM
Last Post: snippsat
  How to print the output of a defined function bshoushtarian 4 1,464 Sep-08-2022, 01:44 PM
Last Post: deanhystad
Sad Want to Save Print output in csv file Rasedul 5 11,601 Jan-11-2022, 07:04 PM
Last Post: snippsat
Photo print output none 3lnyn0 4 1,992 Nov-01-2021, 08:46 PM
Last Post: 3lnyn0
  output correction using print() function afefDXCTN 3 11,458 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  print (output) taaperaban 3 2,042 Sep-03-2021, 04:23 PM
Last Post: deanhystad
  print function output wrong with strings. mposwal 5 3,355 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Print output not working xninhox 7 4,358 Jan-16-2021, 09:42 AM
Last Post: xninhox
  Output with none, print(x) in function Vidar567 3 2,665 Nov-24-2020, 05:40 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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