llxxee
0
Q:

how to save to file in python

def save_to_file(content, filename):
    with open(filename, 'w') as file:
        file.write(content)

import file_operations
file_operations.save_to_file('my_content', 'data.txt')
5
with open('data.txt', 'w') as my_data_file:
   my_data_file.write(WhateverYourInputIs)
# After leaving the above block of code, the file is closed
# "w" overwrites the contents of the file
1

New to Communities?

Join the community