How can I write to a global file inside of a function?
Example:
output_file=open("output_file_name.txt", "w")
def write_to_file:
global output_file
output_file.write('something')
write_to_file()
output_file.close()
The code above is not working. It says “ValueError: I/O operation on closed file”
Any ideas?
write_to_file is a function,
try
othrwise the code is fine