Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Lists Redux Shopping List Take Three

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,627 Points

I'm getting an error, even with the code from the pre-loaded workspace from the next video?

def show_list():
  count = 1
  for item in shopping_list:
    pring("{}: {}".format(count, item))
    count +=1

print("Give me a list of things you want to shop for.")
show_help()

while True:
  new_stuff = input("> ")

  if new_stuff == "DONE":
    print("\nHere's your list:")
    show_list()
    break
  elif new_stuff == "HELP":
    show_help()
    continue
  elif new_stuff == "SHOW":
    show_list()
    continue
  else:

    new_list = new_stuff.spilt(", ")        #line 30 here is where the error is 

    index = input("Add this at a certain spot? Press enter from the end of the list,"
                  "or give me a number. Currently {} items in the list.".format(
        len(shopping_list)))
    if index:
      spot = int(index) - 1
      for item in new_list:
        shopping_list.insert(spot, item.strip())
        spot += 1
    else: 
      for item in new_list:
        shopping_list.append(item.strip())

This is the error I am receiving:

Traceback (most recent call last): File "shopping_list.py", line 30, in <module> new_list = new_stuff.split(", ") AttributeError: 'str' object has no attribute 'split'

I don't get it, because in the next video, when I load the new workspace and run the code that is there, I get the exact error as well.

Advice Kenneth Love?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

So, Workspaces are kind of weird sometimes. Launching the Workspace from the next video will not replace your existing Workspace if you already have one from the course (more or less, there are things we can do to tweak this as teachers). You have to tell it to launch a new one instead of using the existing one you already have for the course if you want to get "caught up" to my version of the code. Otherwise, you just get your code again.

Jason Anders
Jason Anders
Treehouse Moderator 145,627 Points

Thanks Kenneth.

I didn't know that about the Workspaces. I didn't realize the Workspace was loading up the same code and was getting confused and frustrated that even that wouldn't pass.

Thanks for the response though. :) Looking forward to the rest of the Track. (Hopefully with no more silly typos)

1 Answer

Hey Jason,

There's a ton of typos/errors in your code. Line 4 should say print() not pring(). Line 8 isn't a defined function, yet you're trying to call it. On Line 25: spilt() isn't a method — split() is though. Line 27: shopping_list isn't defined. There's probably others...

Jason Anders
Jason Anders
Treehouse Moderator 145,627 Points

Thank You Mikis.

Once I fixed the split() misspelling everything works just fine.

The weird thing is the print/pring (line 4) isn't misspelled in the workspace. Strange?

No problem.

But, what! That is weird. You just copied and pasted and it changed print() to pring()?

Jason Anders
Jason Anders
Treehouse Moderator 145,627 Points

Apparently... :/

Just copy and pasted. I'm beginning to think my computer is possessed. Lol.