Word count program err msg

Hello,
On Windows, I installed Anaconda and Pycharm. From reading the screen, I tried typing in the first program and running it, but got the following error. I created a file in the same path with text. When I ran the prog, I was not sure if I needed to add the full path or not when responding to the interactive prompt, so I added the full path in a var.

See the code, and the error message below.

----------------------------------------------------------------------------------------

file: greg_learning.py

path: c:\Users\Greg Makowski\PycharmProjects\training\

description: CloudXLab, Python course

----------------------------------------------------------------------------------------

infile = ‘C:/Users/Greg Makowski/PycharmProjects/training/text_file.txt’

name = input(‘Enter_file:’)

handle = open(infile, ‘r’)
text = handle.read()
words = text.split()

counts = dict()
for word in words:
counts[word] = counts.get(word, 0) + 1

bigcount = None
bigword = None
for word, count in counts.items():
if bigcount is None or count > bigcount:
bigword = word
bigcount = count
print(bigword + “\t” + str(bigcount))

----------------------------------------------------------------------------------------

C:\ProgramData\Anaconda3\python.exe “C:/Users/Greg Makowski/PycharmProjects/training/greg_learning.py”
Traceback (most recent call last):
File “C:/Users/Greg Makowski/PycharmProjects/training/greg_learning.py”, line 10, in
text = handle.read()
File “C:\ProgramData\Anaconda3\lib\encodings\cp1252.py”, line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: ‘charmap’ codec can’t decode byte 0x9d in position 378: character maps to

Process finished with exit code 1

the indentation did not paste, but existed in the original program in PyCharm.

I was reading the PPT screen from the training class to get the program

resolved. I cut and pasted some text from a PDF. I assumed when I pasted it into PyCharm it would be pasted as plain text, but it had some formatting. I converted it back to plain text and things work now. My bad.

Good to know that it is working fine now :slight_smile: