在笔记本中编写代码的约定。

pidgin的Python项目详细描述


pidgin是ipython魔术的集合,用于创建可计算的文章。

Binder

if__name__=='__main__':%load_extpidgin

降价模式

%pidginmarkdown
---With`pidgin.markdown`,codecellsacceptmarkdown.Anyindentedcodeblocksareexecuted.foo=42print(f"foo is {foo}")>Acceptingthe`pidgin.markdown`convetionmeanstheauthoragreestoindentalltheircodeatleastonce;andsometimesmoreinnestedlists.---

使用pidgin.markdown,代码单元格接受标记。执行任何缩进的代码块。

foo = 42
print(f"foo is {foo}")

Accepting the pidgin.markdown convetion means the author agrees to indent all their code at least once; and sometimes more in nested lists.


foo is 42

模板模式

有了模板,真正的数据可以插入到计算论文中。作者应该希望他们的笔记本重新启动并在模板模式下运行。

%pidgintemplateSkippingthefirstlinesuppressesthemarkdownoutput.
---Intemplatemode,`jinja2`maybeinvokedtotemplatemarkdownandcode.Wealreadyknowthat`foo`is42,butcantestthatassertionwithassertfoois{{foo}}is42{%foriinrange(3)%}print({{i}}){%endfor%}---

在模板模式下,可以调用jinja2来标记和编码模板。我们已经知道foo是42,但是可以用

assert foo is 42 is 42
print(0)
print(1)
print(2)

0
1
2
# Turning off magics%pidgin--offtemplatemarkdown

关闭魔法

%pidgin --off template markdown

山药

---

开始代码
%pidginconventions
---a:42
asserta==42

图形化

graphdigraph

开始代码
!conda install -y graphviz
graph{{IpythonJuliaR}--Jupyter}
  File "<ipython-input-9-1661b3d05729>", line 1
    graph { {Ipython Julia R}--Jupyter}
          ^
SyntaxError: invalid syntax

笔记本电脑作为来源

pidgin使用笔记本作为源代码;保留行号,这样笔记本源代码就可以产生半正常的回溯。

frompidginimportmarkdown,template,conventions

pidgin加载器允许作者直接将笔记本作为源文件导入。这意味着所有的洋泾浜文件都是可导入的。

%%pidginmarkdowntemplateconventionsimportreadme
assertall(file.__file__.endswith('.ipynb')forfilein(markdown,template,conventions))

一切都应该计算

将文档转换为其他格式;重新启动,全部运行,nbconvert

%%pidginmarkdowntemplateUsepidginacellmagictotemporarilyemployanyconvetions.if__name__=='__main__':!jupyternbconvert--tomarkdownreadme.ipynb

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java GridBagLayout不填充区域   java Memozied Fibonacci未运行与常规Fibonacci解决方案   Java Web启动未启动问题   Java中异常和if-then的区别   java从命令提示符运行批处理文件获取错误   socket在Java中验证SSL证书的公共名称   如何在JAVA中检查字符串数组中的相等字   用java语言将音频文件转换成文本文件的语音识别   java为什么foo(1,2,3)没有传递给varargs方法foo(对象…)作为整数[]   java通过蓝牙将奇怪的数据从Arduino传输到Android   java ContainerRequestFilter获取空entitystream   java如何从安卓 studio中删除不兼容类型错误   基本Java错误   在Spring引导中使用REST API时发生java错误   javascript通过从SQL查询派生的URL打开页面