How can I override the built in open
function such that when I call it like so...
with open(file_path, "r") as f:
contents = f.read()
The contents
variable is any string I want?
EDIT: To clarify, I want to be able to just provide a string to the open function rather than a file path that will be read.
with open("foobar") as f:
contents = f.read()
print(contents)
The above should print foobar.
I am aware this is defeating the purpose of open etc but it is for testing purposes.