$ curl cheat.sh/
 text_file = open("Output.txt", "w")
 text_file.write("Purchase Amount: %s" % TotalAmount)
 text_file.close()

#  If you use a context manager, the file is closed automatically for you

 with open("Output.txt", "w") as text_file:
     text_file.write("Purchase Amount: %s" % TotalAmount)

#  If you're using Python2.6 or higher, it's preferred to use
#  `str.format()`

 with open("Output.txt", "w") as text_file:
     text_file.write("Purchase Amount: {0}".format(TotalAmount))

#  For python2.7 and higher you can use `{}` instead of `{0}`
#  
#  In Python3, there is an optional `file` parameter to the `print`
#  function

 with open("Output.txt", "w") as text_file:
     print("Purchase Amount: {}".format(TotalAmount), file=text_file)

#  Python3.6 introduced [f-strings](https://docs.python.org/3/whatsnew/3.
#  6.htmlpep-498-formatted-string-literals) for another alternative

 with open("Output.txt", "w") as text_file:
     print(f"Purchase Amount: {TotalAmount}", file=text_file)

#  [John La Rooy] [so/q/5214578] [cc by-sa 3.0]

$
Follow @igor_chubin cheat.sh