Well, if you’re running it in the same script, it wouldn’t work because when you read it, the file object points to the end of the file, so nothing is returned. To fix that, you have to put in in_data.seek (0) before the 4th line so that it will again point to the beginning of the file.
If you have more questions, refer the Python documentation.