def out_fun(): return "Hello World" output = out_fun() file = open("sample.txt","w") ile.write(output) file.close() #Copy and paste...will work.