Skip to content

Commit

Permalink
Update codapi wasm (#57)
Browse files Browse the repository at this point in the history
use WASM for Python code examples
  • Loading branch information
Oreoxmt authored Jan 6, 2024
1 parent 1f3cb98 commit 408209c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions website/docs/python/time-in-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ print(time.time())
# 1678526843.67069
```

<codapi-snippet sandbox="python" editor="basic" init-delay="500">
<codapi-snippet engine="wasi" sandbox="python" editor="basic" init-delay="500">
</codapi-snippet>

在计算时间差的场景时,如果使用 `time.time()`,那么计算的时间差可能不准确,甚至可能出现负数,具体原因可以参考[日历时钟](#日历时钟-time-of-day-clock)
Expand Down Expand Up @@ -81,7 +81,7 @@ print(time.monotonic())
# 672615.062683958
```

<codapi-snippet sandbox="python" editor="basic" init-delay="500">
<codapi-snippet engine="wasi" sandbox="python" editor="basic" init-delay="500">
</codapi-snippet>

在计算时间差的场景时,使用 `time.monotonic()` 可以保证计算的时间差不会出现负数,具体原因可以参考[单调时钟](#单调时钟-monotonic-clock)
Expand All @@ -97,7 +97,7 @@ print(datetime.datetime.now())
# 2023-03-11 17:33:59.999052
```

<codapi-snippet sandbox="python" editor="basic" init-delay="500">
<codapi-snippet engine="wasi" sandbox="python" editor="basic" init-delay="500">
</codapi-snippet>

在计算时间差的场景时,使用 `datetime.datetime.now()` 计算的时间差是 `timedelta` 对象,是更人类友好的时间差表示方式。但是 `datetime.datetime` 采用的是日历时钟,因此计算的时间差可能不准确,具体原因可以参考[日历时钟](#日历时钟-time-of-day-clock)
Expand Down
12 changes: 10 additions & 2 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
favicon: 'img/logo.png',
stylesheets: [
{
href: "https://unpkg.com/@antonz/codapi@0.10.2/dist/snippet.css",
href: "https://unpkg.com/@antonz/codapi@0.12.0/dist/snippet.css",
},
],
scripts: [
Expand All @@ -29,7 +29,15 @@ export default {
'data-website-id': '7a07d44e-77c0-43c5-aaa3-5071404be998'
},
{
src: "https://unpkg.com/@antonz/[email protected]/dist/snippet.js",
src: "https://unpkg.com/@antonz/[email protected]/dist/snippet.js",
defer: true,
},
{
src: "https://unpkg.com/@antonz/[email protected]/dist/runno.js",
defer: true,
},
{
src: "https://unpkg.com/@antonz/[email protected]/dist/engine/wasi.js",
defer: true,
}
],
Expand Down

0 comments on commit 408209c

Please sign in to comment.