<human>:  Can you show me a Python function to write string to file.
<bot>: Here is a Python function to write string to file

import os

def fwrite(file, data):
  """
  Write a string to a file.
  """
  file.write(data)

# Enter the file name
file_name = "test.txt"

# Calling the function
print((fwrite(open(file_name, "w"), "This is a test")))

#Example Output
# None

#Remember to inspect code for bugs.