Here's my code.
from pathlib import Path
import os
import pprint
os.chdir("E:\New Stuff\Documents\Misc\Python Tutorials\Text Quest\Game Files\Save File 1\Character Save File\")
save_file = open("MySaveFile01.py", "w")
stats = [{"str": 5, "dex": 5, "agi": 5, "end": 5}]
save_file.write('stats = ' + pprint.pformat(stats) + "\n")
save_file.close()
import MySaveFile01
I'm using "Automate the Boring Stuff with Python" as a reference and in chapter 9 on reading and writing files, they say that you can write to a .py file with pretty print to create new files with python code in them and then import that code back into your program. I'm trying to use this to create a save/load system for a game I'm making. The file directories are correct, and the file is created properly. The file contains syntactically correct python code. When I try to import it, it gives me an error saying that there's no module named "MySaveFile01". Why can't I import the file?