Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJan Lundeen
5,887 PointsSplit string - receive AttributeError: 'str' object has no attribute 'available'
Challenge Task 1 of 3 asks me to split a string and assign a new variable called sundaes.
I got the following error when I used the following code:
AttributeError: 'str' object has no attribute 'available'
banana.py available = "banana split;hot fudge;cherry;malted;black and white" sundaes = "banana split;hot fudge;cherry;malted;black and white".split(";".available)
I played around with it and pasted the error into the help section and searched on split and attribute using https://docs.python.org/, but I couldn't find what this error meant. Any suggestions? Thanks!
available = "banana split;hot fudge;cherry;malted;black and white"
sundaes = "banana split;hot fudge;cherry;malted;black and white".split(";".available)
1 Answer
john larson
16,594 Pointsavailable = "banana split;hot fudge;cherry;malted;black and white"
# Use .split() to break the available string apart on the semi-colons (;)
# Assign this to a new variable sundaes
# syntax would look like...
# new variable = first variable.split(";")
Jan Lundeen
5,887 PointsHi John,
Thanks for the encouragement! Good to know I'm not alone.
Just to check my understanding, should my second line should look like this:
sundaes = available.split(";")
I tried sundaes = available.split(";") and it worked. Thanks for your help with this. I didn't realize that it's that simple. And I was thinking I'd have to enter the list. Perhaps that's the beauty of defining the variable (available) first.
Also, I'm not sure if I went to the right place to find help (https://docs.python.org/). Is that the right place? I thought I could copy and paste in the error message to get an idea regarding what I need to correct, but it didn't work. Probably it would be a good troubleshooting reference in the future.
Thanks!
Jan
john larson
16,594 Pointsjohn larson
16,594 PointsJust so you know, this challenge gets a lot of people. And the last part is the worst.