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

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 Intellij通过方法中的包查找用法   java中VS代码和打包命名的问题   将java CMS功能集成到具有高度动态内容的网站(Lucene/Mysql/Nosql)的策略   oracle的java类强制转换异常。jdbc。驾驶员OracleConnection   字节码向JVM添加上指令   如何在抽象类中执行java方法?   java是否可以在apache访问日志中排除指定的GET参数?(作者:W7开发环境)   java如何获取已安装音频播放器的列表?   尝试向HS学生展示如何使用Java访问MS数据库   使用正则表达式java对给定行中的特定字符串进行计数   java JOOQ Select查询中的Select计数   方法Java,如何从二维双精度数组中找到特定值?   获取图像URL的java正则表达式   java在切换到新的窗口驱动程序后找不到元素