Ipython 使用pep8检查jupyter笔记本中的编码样式
我在使用pep8检查jupyter笔记本中的编码样式时遇到问题 安装人: 在[1]Ipython 使用pep8检查jupyter笔记本中的编码样式,ipython,jupyter,pep8,Ipython,Jupyter,Pep8,我在使用pep8检查jupyter笔记本中的编码样式时遇到问题 安装人: 在[1] %install_ext https://raw.githubusercontent.com/SiggyF/notebooks/master/pep8_magic.py 出去 装载 在[2] 出去 利用它 在[3] 出去 --------------------------------------------------------------------------- TypeError回溯(最近一次调用上次
%install_ext https://raw.githubusercontent.com/SiggyF/notebooks/master/pep8_magic.py
出去
装载
在[2]
出去
利用它
在[3]
出去
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
---->1获取\u ipython()。运行\u cell\u magic(u'pep8',u'',u'\na=1')
/run_cell_magic中的usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc(self,magic_name,line,cell)
2118 magic_arg_s=self.var_expand(行、堆栈深度)
2119带自建存水弯:
->2120结果=fn(魔法参数,单元格)
2121返回结果
2122
/pep8中的home/cs/.ipython/extensions/pep8_magic.pyc(行,单元格)
38使用tempfile.NamedTemporaryFile()作为f:
39#保存到文件
--->40 f.写入(字节(单元+'\n',UTF-8'))
41#确保它是书面的
42 f.冲洗()
TypeError:str()最多接受1个参数(给定2个)
似乎我已经成功安装并加载了它,但我无法运行cell magic
后来我发现问题是由python2和python3之间的一些差异引起的。通过在pep2\u magic.py
中使用io.Bytes
和f.write(cell+'\n')
,它成功了。但不幸的是,它仍然不能输出pep8的信息,就像这里的例子一样
Installed pep8_magic.py. To use it, type:
%load_ext pep8_magic
%load_ext pep8_magic
The pep8_magic extension is already loaded. To reload it, use:
%reload_ext pep8_magic
%%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)