Possible Duplicate:
builtins.TypeError: must be str, not bytes
I wrote a program to write a dict to file and in Python 2.7 it works well, but now in Python 3 I receive TypeError: 'str' does not support the buffer interface
and TypeError: must be str, not bytes
CODE UPDATED
Inputs: path to dir, file name (!hamers.txt
for example) and new dictionary
Outputs: none
Effects: Generate new file with dictionary. Check if file exists and then merge two dictionaries (existing and new).
def generate_file_from_dict(self, path, fname, my_new_dict):
mfile = self.add_slash(path)+fname
if os.path.exists(mfile):
mfile = open(mfile, 'rb')
my_existing_dict = pickle.load(mfile)
my_new_dict = dict(my_existing_dict.items() + my_new_dict.items())
mfile.close()
mfile = open(self.add_slash(path)+fname, 'wb+')
pickle.dump(my_new_dict, mfile)
mfile.close()
Now its
my_existing_dict = pickle.load(mfile)
EOFError