How to output Python to both the screen and the file log

I know that using python xxxx.py > 1.log on the command line can output the results of the program to 1.log. But if you run it like this on the command line, you won"t see the real-time print results, so you can only wait for the program to settle and then check the contents of the 1.log. Is there any way to output the results in real time or to output the log to a file?

Sep.08,2021

-sharp 
python xxxx.py|tee 1.log

-sharp 
python xxxx.py|tee -a 1.log

if there is no tee command on the system, install the command

-sharp Debian 
apt -y install coreutils

-sharp Redhat 
yum -y install coreutils

you can execute python xxxx.py > 1.log & so that the process takes place in the background, which you can see through jobs. The log is written in 1.log . Then if you want to view the log in real time, you can use tail-f 1.log .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4f52f-43cdd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4f52f-43cdd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?