Joy 宇 2023-01-12 09:07 采纳率: 77.8%
浏览 41
已结题

(python website) 网頁从其他 python 脚本获取输出, 遇 model not found error

根据文章 https://stackoverflow.com/questions/6086047/get-output-of-python-script-from-within-python-script

我创建了 在线网页 (.html) 运行其他 .py 脚本,也就是 import 自己的脚本,结果遇 model not found error

逻辑上似乎 python 代码没问题,可能是设置错误或其他我自己没有想到的问题

  • printbob.py
import sys

def main(args):
    for arg in args:
        print(arg)

if __name__ == '__main__':
    main(sys.argv)
  • test_0109_003.html
<html>
    <head>
      <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
      <script defer src="https://pyscript.net/latest/pyscript.js"></script>
    </head>
  <body>
    <b><p>title test 1.10-test_get_ print  </p></b>
    <br>


  
    <py-script>
      import printbob

      printbob.main('arg1 arg2 arg3 arg4'.split(' '))
      
    </py-script>
  </body>
</html>
  • (pic 01) 网站显示结果

    enter image description here


  • (pic 02)确认有把 .py 和 .html 脚本放在 WinSCP,在线主机系统,但 import model not found

    enter image description here

那么该如何解决这个问题

  • 写回答

1条回答 默认 最新

  • machineShunMing 2023-01-15 11:03
    关注
    <html>
      <head>
        <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
        <script defer src="https://pyscript.net/latest/pyscript.js"></script>
      </head>
      <body>
        <py-script src="1.py">
       
        </py-script>
        
      </body>
    </html>
    

    1.py

    args='arg1 arg2 arg3 arg4'.split(' ')
    for arg in args:
            print(arg)
     
    

    试试看把脚本引入进来,参考https://docs.pyscript.net/latest/reference/elements/py-script.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 2月7日
  • 已采纳回答 1月30日
  • 创建了问题 1月12日

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。