使用pep8检查jupyter笔记本中的编码风格

时间:2016-04-13 14:28:41

标签: ipython jupyter pep8

我在使用pep8检查jupyter笔记本中的编码风格时遇到了问题。

安装:

[p]中的

%install_ext https://raw.githubusercontent.com/SiggyF/notebooks/master/pep8_magic.py

Installed pep8_magic.py. To use it, type:
  %load_ext pep8_magic

加载

在[2]

%load_ext pep8_magic

The pep8_magic extension is already loaded. To reload it, use:
  %reload_ext pep8_magic

通过

使用它

在[3]

%%pep8
a=1

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-3b6f6dbc7761> in <module>()
----> 1 get_ipython().run_cell_magic(u'pep8', u'', u'\na = 1')

/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell)
   2118             magic_arg_s = self.var_expand(line, stack_depth)
   2119             with self.builtin_trap:
-> 2120                 result = fn(magic_arg_s, cell)
   2121             return result
   2122 

/home/cs/.ipython/extensions/pep8_magic.pyc in pep8(line, cell)
     38     with tempfile.NamedTemporaryFile() as f:
     39         # save to file
---> 40         f.write(bytes(cell + '\n', 'UTF-8'))
     41         # make sure it's written
     42         f.flush()

TypeError: str() takes at most 1 argument (2 given)

似乎我已成功安装并加载它,但我无法运行单元魔法。

后来我发现问题是由python2和python3之间的一些差异引起的。在io.Bytes中使用f.write(cell+'\n')pep2_magic.py,就可以了。但不幸的是,它仍然无法输出pep8的信息,就像这里的示例pep8 style guide

0 个答案:

没有答案