The author uses the Unix system and you are using the windows system and the only difference between the two examples is the file-separator.
In Python, you can declare separators either with hard-coded (For Unix: /
, for windows: \
)
But you can use os.path
to remove the confusion of the os separator. Just place the text file in your current directory and you can use it in the example like below:
import os.path
text_file = 'pi_digits.txt'
file_path = os.path.join(os.getcwd(), text_file)
print(file_path)
Out:
/Users/PycharmProjects/StackOverFlow-pip/pi_digits.txt
Since I'm also using a Unix system my example is similar to the book example. But If you try it in your pc you will see similar to the below:
'D:\PycharmProjects\Standard_Library\pi_digits.txt'
Then you can open the text file and read it using with open(file_path) as file_object: