How can I create and append the output of my code to a txt file? I have a lot of code.
This is just a small example of what I'm trying to do:
def output_txt():
def blop(a,b):ans = a + b
print(ans)
blop(2,3)
x = 'Cool Stuff'
print(x)
def main(x):
f = open('demo.txt', 'a+')
f.write(str(output_txt))
f.close
main(x)
f = open('demo.txt', 'r')
contents = f.read()
print(contents)
But the output gives me this:
cool bananas<function output_txt at 0x0000017AA66F0F78><function output_txt at 0x0000017AA66F0B88><function output_txt at 0x0000017AA66F0948>