日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 生成html文件浏览器_Handout库:能将python脚本转化为html展示文件

發布時間:2024/7/5 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 生成html文件浏览器_Handout库:能将python脚本转化为html展示文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

有的時候我們需要將python代碼進行展示講解,這個時候使用py文件進行講解效果并不是最好的。如果能轉化為html文件,在瀏覽器中展示,那就完美了。好消息是存在一個名為handout的庫可以實現我們的設想。

安裝

pip3 install

U handout

快速學習

下面是demo.py文件中的代碼及注釋,其中handout庫可以將注釋部分中的markdown標記轉化為html相應的樣式

"""

# Python Handout庫

將python腳本轉化為帶markdown標記形式的html文件

"""

import

handout

import

matplotlib

.

pyplot

as

plt

import

numpy

as

np

"""## 定義輸出的文件夾"""

doc

=

handout

.

Handout

(

'output'

)

"""

## Markdown注釋

以前后3個"

內的部分作為

markdown

待識別區域,可以用

markdown

語法書寫注釋

例如,

handout

中出現下面的無序列表

-

Headlines

-

Hyperlinks

-

Inline

`code()`

snippets

-

**

Bold

**

and

*

italic

*

"""

"""

## 添加文本和變量

注意這里使用

doc

.

add_text

方法向

handout

中添加運行結果,類似于

python

中的

print

"""

for

index

in

range

(

3

):

doc

.

add_text

(

'Iteration'

,

index

)

doc

.

show

()

"""

## 添加matplotlib圖

在handout中添加matplotlib圖

"""

fig

,

ax

=

plt

.

subplots

(

figsize

=(

4

,

3

))

ax

.

plot

(

np

.

arange

(

100

))

fig

.

tight_layout

()

doc

.

add_figure

(

fig

)

doc

.

show

()

"""

設置handout中圖片的尺寸

"""

for

iteration

in

range

(

3

):

fig

,

ax

=

plt

.

subplots

(

figsize

=(

3

,

2

))

ax

.

plot

(

np

.

sin

(

np

.

linspace

(

0

,

20

/

(

iteration

+

1

),

100

)))

doc

.

add_figure

(

fig

,

width

=

0.33

)

doc

.

show

()

"""

## 添加圖片

This requires the `imageio` pip package.

"""

image_a

=

np

.

random

.

uniform

(

0

,

255

,

(

200

,

400

,

3

)).

astype

(

np

.

uint8

)

image_b

=

np

.

random

.

uniform

(

0

,

255

,

(

100

,

200

,

1

)).

astype

(

np

.

uint8

)

doc

.

add_image

(

image_a

,

'png'

,

width

=

0.4

)

doc

.

add_image

(

image_b

,

'jpg'

,

width

=

0.4

)

doc

.

show

()

"""

## 瀏覽handout

默認doc.show()輸出到output文件夾中的index.html文件

"""

輸出結果

下面左側是代碼,右側是轉化后的html文件效果。

下面是demo.py文件的運行過程及結果的動態展示

總結

以上是生活随笔為你收集整理的python 生成html文件浏览器_Handout库:能将python脚本转化为html展示文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。