text = '''Some random data ''' # write to data.txt with open('data.txt', 'w') as f: f.write(text) # append to data.txt with open('data.txt', 'a') as f: f.write(text)