I am trying to understand the class L and in particular its method .attrgot(). I am working through lecture 2, the bears example.

I have read the docs and understand that L is a fastai class that is basically a modified list. I also understand that .attrgot() creates a new instance of L that contains the attributes specified in the method. But the example uses results.attrgot('content_url'). It’s the “content_url” that is confusing me. That string does not appear in results. Where does this string come from and what is it matching with?


Were you able to execute the code and get the results?

From https://fastcore.fast.ai/foundation.html#L.attrgot
Allows to get the key ‘content_url’ from each item (dict) in the results.

If you could get able to print the results, it may be easier.

Thanks, I get it now. “content.url” is an attribute of the Azure ImageObject. So attrgot creates a new L of the urls in that attribute.

I thought it was a fastai term, but it’s in the Azure docs.

In case anyone else is looking here is the webpage


please can someone help. why am i having this error in 02_production?

Could you check if the API token is correct??? There seems to be some additional invalid characters

Please check API key in Azure website and try again.

I have resolved the issue. thanks a lot guys!

Hi I have had similar problems trying to get the chapter 2 example to work. I get different error messages every time I run it. I know I got it to work once, but I haven’t gotten it to work since.

Why does it do something different every time I run it? Is this a common issue?

@Mark and @msivanes just checked out the ImageObject Class of Azure, the attribute is ‘ContentUrl’, not ‘content_url’. How did it end up as ‘content_url’ in the notebook?


Hi, @mariasimon. It’s been a while since I’ve looked at this. Looking at the docs, you seem to be right.

I don’t have an answer to your question, and I don’t use Azure enough to spend the time to try to figure it out. My guess is that something is generating a dictionary, and that .attrgot() is accessing that dictionary with ‘content_url’ as the key. In this case, it’s not invoking the object attribute directly, but a dictionary that is somehow generated. But it’s just a guess. You can try playing with the results object see what you can find.

Sorry that I’m not more help.

Added: Try results['content_url'] and if it returns anything; if it does, a dictionary must exist.

1 Like

I checked the ‘results’ list. It’s contentUrl in there.
ims = results.attrgot(‘content_url’) just creates a list of 150 ‘None’ values.

ims is hardcoded in the next step, so it doesn’t matter.

thanks @Mark_F for the quick reply

No, it actually is a fastai term. It is from the class L, which is introduced by fastai

results is itself from L class. It is similar to a list of dictionaries. print(results) will show you the elements. It has a particular key: ‘contentUrl’. So results.attrgot(‘contentUrl’) will return all the dictionaries with the key ‘contentUrl’.

Thanks for the replies.

Honestly, I don’t remember this that well, and haven’t looked in months. But the reason there is a dictionary with the key ‘contentUrl’ is presumably that the Azure api put it there. That’s what I was trying to say. ‘contentUrl’ as a key is not from fastai, it’s from Azure. The L class is a fastai class.

As pointed out, it does not match ‘content_url’ in the notebook.

Yeah, I ran into this same exact problem. Has this been updated? Doesn’t look like it in the most recent version of the notebooks for this lecture (as far as I’ve seen).

Gotcha. Okay that makes sense now. Thanks for sharing this.