Exercise 41 Issue Running Script

When I run the oop_test.py script provided in Exercise 41, I get the following error.

Traceback (most recent call last):
  File "oop_test.py", line 75, in <module>
    question, answer = convert(snippet, phrase)
  File "oop_test.py", line 48, in convert
    result = sentence.copy()
AttributeError: 'str' object has no attribute 'copy'

I can’t seem to determine what the problem is, especially since it is copied straight from Zed. Also, the script worked for him in the video. Maybe something with my system/setup?

I’m running on a bash shell with Linux Subsystem on Windows if that matters.

****** Edit ******
I noticed on Zed’s GitHub page for Exercise 41 that another version of the oop_test.py was there and I reran the script with that version and it worked.

If my version worked and yours didn’t then it might instructive to find out what the difference is. You can do this in two ways. First, you can try to debug it yourself and figure out the cause. Remember that you have to print out variables to debug. Don’t stare at the code to figure it out. I’m doing this repeatedly in the videos and mentioning this all the time. To do that you’d toss this in right above that line:

print(">>>> sentence=", sentence)

Then work backwards from there printing more variables and paths. That would be the most instructive, but also take longer. If you want to just find out what the difference is, use the diff tool:

diff oop_test.py ex41.py

That’ll show you what’s different between my version (ex41.py) and yours (oop_test.py).

1 Like