![](/img/trans.png)
[英]Can't I simply copy and paste a program from a Jupyter notebook to a file.py?
[英]run two file.py one after the other in jupyter notebook
我正在使用jupyter筆記本。
我有兩個帶有兩個腳本的文件:script1.py和script2.py
雖然文件script1.py在while循環中每分鍾運行一次,但我想在同一循環中運行script.1后4分鍾運行script2.py。
這就是我到目前為止所擁有的:一個腳本,該腳本每分鍾在一個循環中運行script1.py,睡眠時間為一分鍾。
starttime=time.time()
while True:
%run "script1.py"
time.sleep(60.0 - ((time.time() - starttime) % 60.0))
在哪里可以將%run“ script2.py”添加到此代碼中?
也許你可以做類似的事情
starttime= time.time()
while True:
%run "script1.py"
time.sleep(60.0 - ((time.time() - starttime) % 60.0))
if( (starttime - time.time()) > 240): %run "script2.py"
只需檢查是否已經過了4分鍾,然后運行script2即可:
starttime=time.time()
while True:
%run "script1.py"
if (time.time() - starttime) >= 240.0
%run "script2.py"
time.sleep(60.0 - ((time.time() - starttime) % 60.0))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.