Is there a way to write in file like in shell script but in python by doing something similar to this:
cat >> document.txt <<EOF
Hello world 1
var=$var
Hello world 2
EOF
?
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.
If I understand the question correctly, you are referring to the here document feature in bash. I don’t think there is a direct equivalent in Python, but you can enter multi-line strings using
"""(triple quotes) to delimit the start and end, e.g.which you could then write to a file:
and achieve much the same thing as your bash example.