私は、transcryptによって提供される Get started の部分に従い、 hello という名前のフォルダーを作成してから、2 つのファイルを作成しましたhello.py
。hello.html
私の目標は、クライアント側で関数を実行し、結果を Web ページに出力することです。
hello.py
from datetime import datetime
import time
import random
def FUN():
for i in range(random.randrange(1, 9)):
time.sleep(random.randrange(10 , 30 ))
print (f"Current time {datetime.now()} , Number {i}")
hello.html
<script type="module">import * as hello from './__target__/hello.js'; window.hello = hello;</script>
<p>
<div id = "FUN">...</div>
<button onclick="hello.FUN()">Do code</button>
サーバーを起動しpython3 -m http.server
、hello.html にサーフィンしました
ボタンを押してもコードを実行しても何も得られません
[08/May/2021 04:30:16] "GET /hello.html HTTP/1.1" 200 -
127.0.0.1 - - [08/May/2021 04:30:17] code 404, message File not found
127.0.0.1 - - [08/May/2021 04:30:17] "GET /__target__/hello.js HTTP/1.1" 404 -
127.0.0.1 - - [08/May/2021 04:30:17] code 404, message File not found
127.0.0.1 - - [08/May/2021 04:30:17] "GET /favicon.ico HTTP/1.1" 404 -
コマンドでトランスクリプトをインストールしますpip3 install transcrypt
しかし、このコマンドを実行したときpython -m transcrypt -b -m -n hello.py
この出力で中止されました
Saving target code in: /home/kali/n3w/__target__/org.transcrypt.__runtime__.js
Saving target code in: /home/kali/n3w/__target__/re.translate.js
Saving target code in: /home/kali/n3w/__target__/re.js
Saving target code in: /home/kali/n3w/__target__/warnings.js
Error while compiling (offending file last):
File '/home/kali/n3w/hello.py', line 1, at import of:
File '/home/kali/.local/lib/python3.9/site-packages/wget.py', line 562, at import of:
File '/usr/lib/python3.9/optparse.py', line 90, at import of:
File '/usr/lib/python3.9/gettext.py', line 718, at import of:
File '/usr/lib/python3.9/locale.py', line 658, at import of:
File '_bootlocale', line 8, namely:
Import error, can't find any of:
/home/kali/n3w/locale.py
/home/kali/n3w/locale.js
/home/kali/.local/lib/python3.9/site-packages/transcrypt/modules/locale.py
/home/kali/.local/lib/python3.9/site-packages/transcrypt/modules/locale.js
/home/kali/n3w/locale.py
/home/kali/n3w/locale.js
/home/kali/n3w/_bootlocale.py
/home/kali/n3w/_bootlocale.js
/home/kali/.local/lib/python3.9/site-packages/transcrypt/modules/_bootlocale.py
/home/kali/.local/lib/python3.9/site-packages/transcrypt/modules/_bootlocale.js
/home/kali/n3w/_bootlocale.py
/home/kali/n3w/_bootlocale.js
/home/kali/n3w/_locale.py
/home/kali/n3w/_locale.js
/home/kali/.local/lib/python3.9/site-packages/transcrypt/modules/_locale.py
/home/kali/.local/lib/python3.9/site-packages/transcrypt/modules/_locale.js
/home/kali/n3w/_locale.py
/home/kali/n3w/_locale.js
/usr/lib/python3.9/_locale.py
/usr/lib/python3.9/_locale.js
/usr/lib/python3.9/lib-dynload/_locale.py
/usr/lib/python3.9/lib-dynload/_locale.js
/home/kali/.local/lib/python3.9/site-packages/_locale.py
/home/kali/.local/lib/python3.9/site-packages/_locale.js
/home/kali/testing_0505/npm_socket/batavia/_locale.py
/home/kali/testing_0505/npm_socket/batavia/_locale.js
/usr/local/lib/python3.9/dist-packages/_locale.py
/usr/local/lib/python3.9/dist-packages/_locale.js
/usr/lib/python3/dist-packages/_locale.py
/usr/lib/python3/dist-packages/_locale.js
/usr/lib/python3.9/dist-packages/_locale.py
/usr/lib/python3.9/dist-packages/_locale.js
Transcrypt サイトには、小さなデモをセットアップする手順が記載されていますが、各コマンドの動作については詳しく説明されていません。