Re: Printing to a file and a terminal at the same time

2017-10-10 Thread MRAB

On 2017-10-10 17:00, Vail, Rick wrote:

I have a script for Cisco devices that will do configuration or any CLI 
command.  What I would like to do is print the output to my terminal(windows) 
and to a file. I can come up with stdout parameters
To print to a file but not to the screen and when I remove the stdout part it 
prints to the screen only.

This prints to a file
filename  = open("outputfile",'w')
sys.stdout = filename
print ("Anything printed will go to the output file")

Remove the above and it prints to the terminal, help


Why not define a function that does both?

def my_print(*args, **kwargs):
print(*args, **kwargs)
print(*args, **kwargs, file=output_file)
--
https://mail.python.org/mailman/listinfo/python-list


RE: Printing to a file and a terminal at the same time

2017-10-10 Thread Vail, Rick
I have a script for Cisco devices that will do configuration or any CLI 
command.  What I would like to do is print the output to my terminal(windows) 
and to a file. I can come up with stdout parameters
To print to a file but not to the screen and when I remove the stdout part it 
prints to the screen only.

This prints to a file
filename  = open("outputfile",'w')
sys.stdout = filename
print ("Anything printed will go to the output file")

Remove the above and it prints to the terminal, help



Rick Vail | Network Engineer
Presidio (NASDAQ: PSDO) | www.presidio.com
12272 Hancock St, Carmel, IN 46032
D: 317.428.6399 | C: 317.847.0493 | 
rv...@presidio.com



[Future. Built.]


Follow us:

[Follow Presidio on Twitter]





This message w/attachments (message) is intended solely for the use of the 
intended recipient(s) and may contain information that is privileged, 
confidential or proprietary. If you are not an intended recipient, please 
notify the sender, and then please delete and destroy all copies and 
attachments. Please be advised that any review or dissemination of, or the 
taking of any action in reliance on, the information contained in or attached 
to this message is prohibited.
-- 
https://mail.python.org/mailman/listinfo/python-list