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

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获取JEditorPane中字符的绝对位置   java Datetime:将时间段拆分为天、小时和分钟   java是使此HashMap更高效的一种方法   java项目reactor:collectList()之后的block()对Flux不起作用。创建()   java在Mac OSX上安装OpenCV   java递归地确定一组数字是否包含两个总和相等的子集   Quad2D曲线上的几何图形Java绘图箭头   java将SSL证书导入Glassfish 4。十、   java Android未找到处理Intent MediaScanner的活动   EclipseJava。安全cert.CertificateParsingException:java。木卫一。IOException:主题密钥,无法创建EC公钥   java我能在O(M log N)时间内完成吗?   java跟踪eclipse中的资源更改也在中。元数据和。项目   java如何完全禁用Android键盘   java返回到上一个活动