Problems with a code sample from a book

In the future, please make sure to show a proper minimal, reproducible example when asking questions about programming anywhere online. That will make it easier to understand the problem, and ensure that there hasn’t been some unrelated problem (e.g. forgetting to save changes to a file before running it). The code that you show in the first question can’t possibly be right, because a path like “C:\Users\tech_worker\segismundo.txt” will not work - the quotes are wrong, and the backslashes are not escaped. Although I think both of these happen simply because you have not properly formatted the code, as described in the pinned thread.

As you found, the problem was with specifying the encoding for the open call, but your original code shows that being done properly - so that can’t be what actually went wrong. It’s important to be able to reproduce problems in order to talk about them properly.