Python Print String To Text File


In case you want to pass multiple arguments you can use a tuple

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

More: Print multiple arguments in python


I'm using Python to open a text document:

text_file = open("Output.txt", "w")

text_file.write("Purchase Amount: " 'TotalAmount')


I want to enter the string called "TotalAmount" into the text document. Can someone please let me know how to do this?

this is the example of Python Print String To Text File

def my_func():
    this function return some value
    return 25.256

def write_file(data):
    this function write data to file
    :param data:
    file_name = r'D:\log.txt'
    with open(file_name, 'wb') as x_file:
        x_file.write('{} TotalAmount'.format(data))

def run():
    data = my_func()