2017-05-16 7 views
0
names, plot_dicts = [], [] 
for repo_dict in repo_dicts: 
    names.append(repo_dict['name']) 
    plot_dict = { 
     'value': repo_dict['stargazers_count'], 
     'label': repo_dict['description'], 
     'xlink': repo_dict['owner']['html_url'], 
     } 
    plot_dicts.append(plot_dict) 

my_style = LS('#333366', base_style=LCS) 
chart = pygal.Bar(style=my_style, x_label_rotation=45, show_legend=False) 
chart.title = 'Most-Stared Python Project On Github' 
chart.x_labels = names 
chart.add('', plot_dicts) 

chart.render_to_file('new_repos.svg') 

*이 스크립트를 실행하면 오류가 발생합니다.AttributeError : 'NoneType'객체에 '디코드'속성이 없습니다.

Traceback (most recent call last): 
    File "new_repos.py", line 54, in <module> 
    chart.render_to_file('new_repos.svg') 
    File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\public.py", line 114, in render_to_file 
    f.write(self.render(is_unicode=True, **kwargs)) 
    File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\public.py", line 52, in render 
    self.setup(**kwargs) 
    File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\base.py", line 217, in setup 
    self._draw() 
    File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\graph.py", line 933, in _draw 
    self._plot() 
    File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\bar.py", line 146, in _plot 
    self.bar(serie) 
    File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\bar.py", line 116, in bar 
    metadata) 
    File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\util.py", line 234, in decorate 
    metadata['label']) 
    File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\_compat.py", line 62, in to_unicode 
    return string.decode('utf-8') 
AttributeError: 'NoneType' object has no attribute 'decode' 

*이 나는이에 코드의 일부를 변경하는 경우, 오류가 사라집니다 어떻게 이제까지 * 그러나 설명은 차트에서 무시됩니다.

names, plot_dicts = [], [] 
for repo_dict in repo_dicts: 
    names.append(repo_dict['name']) 
    plot_dict = { 
     'value': repo_dict['stargazers_count'], 
     #'label': repo_dict['description'], 
     'xlink': repo_dict['owner']['html_url'], 
     } 
    plot_dicts.append(plot_dict) 

* 왜이 문제로 나를 도와 줄 수 있습니까?

+0

텍스트 오류가 좋을 것 같습니다. –

답변

0
'label':str(repo_dict['description']) 

해보십시오 STR()는 위와 같이, 당신이있어 데이터 이전 '설명'storged 그 값의 유형을 clarifed하지 않은 것 같다.

+0

고마워, 나는 시도 할 것이다! –