I have some Python3 code that opens a file in write mode, writes something to it, and then closes the file. The filename is an int
. For some reason, the code doesn't work as expected. When I run the f.write()
statement, a 6
is printed to the screen. And when I run the f.close()
statement, the string that was supposed to be written is printed to the screen.
>>> f = open(2, 'w')
>>> f.write('FooBar')
6
>>> f.close()
FooBar>>>
>>>
I checked the directory that I ran this in and the file (named 2
) was not created. Can anyone explain what is going on? I suspect it has to do with the filename being an int
, but I'm not sure.