Is there any alternatives to the print statement for output in Python.
Also, how can I format my output text to be color-coded?
I’m a beginner programmer, pretty new to it.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Is one alternative. You can also write to
sys.stderr. Personally, I usesys.stdoutwhen I need to pass a generic “stream” to some function that will write to it. And open file is a stream, andsys.stdoutis a stream. This way my function can be parametrized to write either to output or to file.I also find
sys.stdout.writemore convenient thanprintfor printing many things to a single line, as I find the ending comma syntax ofprintfor suppressing the newline ugly and inconvenient.Regarding printing to the terminal in colors, see this other SO discussion.