I'm trying to write some text directly into a python file that I intend to store data in a dictionary. The script runs and works perfectly and writes the data I need into a key-value pair within the dictionary of the file. However when the script finishes and I check the file, at the very top of the file I get a string of diamond shapes with a question mark in them.
This is the code:
def add_new_value(key, var):
total = ",'"+key+"'"+":"+var+" #$%$#"
print(total)
with open("TheseusDictionary.py","r+", encoding = "utf-8") as intent:
read=intent.read()
with open("TheseusDictionary.py", "w+", encoding = "utf-8") as far:
print("second phase complete")
print(read)
read = read.replace("#$%$#",total)
intent.write(read)
add_new_value("False", "1")
#$%$# is a comment within my dictionary file that I use to tell at what point in the file to insert the key-value pair. What's causing these characters at the top of the file?