You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working in Chapter 17 setting up custom tooltips (pp 388-389) I ran into the issue where the description for the project 'shadowsocks' was None. When the project is run you get a 'AttributeError: 'NoneType' object has no attribute 'decode'' exception when you try to render.
To get around this I had to add a None checker before I populate the plot_dict data, something like this:
forrepo_dictinrepo_dicts:
# Cleans any none values and replaces with empty stringfork, vinrepo_dict.items():
ifvisNone:
repo_dict[k] =''names.append(repo_dict['name'])
plot_dict= {
'value': repo_dict['stargazers_count'],
'label': repo_dict['description']
}
plot_dicts.append(plot_dict)
Not sure this is the fastest way of doing it but it worked for me.
The text was updated successfully, but these errors were encountered:
You and I came up with similar approaches. Here's what I wrote for the update:
names, plot_dicts= [], []
forrepo_dictinrepo_dicts:
names.append(repo_dict['name'])
# Some projects lack a description, which causes an error when # labeling bars. Specify a label if there's no description.description=repo_dict['description']
ifnotdescription:
description="No description provided."plot_dict= {
'value': repo_dict['stargazers_count'],
'label': description,
}
plot_dicts.append(plot_dict)
We pull the description from the repo_dict, and then change the description if none is provided. We don't change the repo_dict itself. Same result though, so nice work troubleshooting!
Couldn't get the entire block of code to formate correctly(for statement should be in the code block) but I think it still makes sense.
You can start a code block with triple backticks followed by python, and close the code block with another set of triple backticks. This formats your code with python syntax highlighting. I edited the formatting of your code block with this style.
When working in Chapter 17 setting up custom tooltips (pp 388-389) I ran into the issue where the description for the project 'shadowsocks' was None. When the project is run you get a 'AttributeError: 'NoneType' object has no attribute 'decode'' exception when you try to render.
To get around this I had to add a None checker before I populate the plot_dict data, something like this:
Not sure this is the fastest way of doing it but it worked for me.
The text was updated successfully, but these errors were encountered: