425KB在浏览器里看波形

全部文件在这里。无需上网即可使用,自带了jquery.min.js等。页面最下面有作者信息, 不是我做的, 我只是下载删减压缩了一番。不好意思少了行 port = int(sys.argv[1])

What is a Value Change Dump (VCD) file? 博客园 

python可到这里下载,总归是很有用的。python可能自带flask包,没带的话pip install flask很快。pip 使用国内镜像源 | 菜鸟教程

  • python-3.10.0a7-amd64-webinstall.exe 06-Apr-2021 10:47 1.2 MB
  • python-3.10.0a7-amd64.exe 06-Apr-2021 10:47 26.29 MB
  • python-3.10.0a7-embed-amd64.zip 06-Apr-2021 10:48 7.96 MB

不知道.zip和.exe有啥差别,我装的是3.9-amd64.exe. 用python做个HTTP server,界面用HTML+CSS+JavaScript来写不错——不用学那么多东东了。用JS写的UI框架多如牛毛,功能强大,普通的界面都能应付。python自带HTTP server:

复制代码
from http.server import *
class HTTPReqHandler(SimpleHTTPRequestHandler):
    def __init__(m, r, c, s): super().__init__(r, c, s, directory='www')
    def do_GET(m):
        path = m.requestline.split(' ')[1]
        if not path.startswith('/ucci'): return super().do_GET()
        m.send_response(200)
        m.send_header('Content-type', 'text/html')
        m.end_headers()
        ee.send('hi')
def do_HEAD(m): super().do_HEAD() def do_POST(m): super().do_POST()
复制代码

一直满足于GET,昨天才发现SimpleHTTPRequestHandler没实现do_POST(). 所以试了flask:

复制代码
try: from flask import Flask, jsonify, send_file, request
except: print("This program needs flask; please run 'pip install flask' first.")

app = Flask(__name__, root_path='www')

@app.route('/')
def send_index_html(): return send_file('index.html')
# Flask返回个对象app,它有成员函数route,which is a decorator.
# 描述了规则: GET / ? 发index.html

@app.route('/parse-vcd', methods = ['POST']) # 处理POST /parse-vcd
def parse_vcd():
    try: content = request.json['content']
    except KeyError: logging.error('No content, try to open the file locally.')
    try: fname = request.json['fname']
    except KeyError: logging.error('No filename')
    logging.info(f'File to parse: {fname}')
    try:
        data = parseFile(os.path.join(here, fname), content)
        return jsonify(data)
    except Exception as e: logging.error(f'Error: {e}')

@app.route('/<path:path>') # 没这个不行啊!
def send_others(path):  return send_file(path)

os.environ["FLASK_ENV"] = 'development'
app.run(port=8000, debug=False)
复制代码

把debug设成True后,flask会重启你的脚本,__name__ == "__main__"判断不了。Spawn a new Python interpreter with the same arguments as the current one, but running the reloader thread.

低版本的jquery-ui.min.js不检查e.browser.msie是否存在(try catch包起来),导致pane分隔条不能拖动,把e.browser.msie替换为0后ok.

The flask object implements a WSGI application and acts as the central object. It is passed the name of the module or package of the application.Once it is created it will act as a central registry for the view functions, the URL rules, template configuration and much more. Web服务器网关接口(Python Web Server Gateway Interface, WSGI)是为Python语言定义的Web服务器和Web应用程序或框架之间的一种接口。

CGI (Common Gateway Interface)最早,HTTP服务器每次去执行.exe,效率低。后来有了FastCGI, 它也是个server,和HTTP server之间通过socket等通信。后来有了PHP和ASP,HTTP服务器带解释功能。我觉得这个很好,大段的printf("<a href=\"....\">xxx</a>")实在是太繁琐了。然后serverlet啦,soap啦,好比http;//host/prog, 在server端真有个prog类/module…… 重大发明?Sun早就有RPC(Remote Procedure Call)了。噢,还曾有调用.dll/.so的版本。总之,人类很会printf. 为啥我要么这么说? python有个logging模块,自称受log4j的启迪,颜色丰富,能报文件名和行号。问题是:a.py调b.py调c.py,别光出来一行 c.py:250啊!

posted @   Fun_with_Words  阅读(130)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?









 和4张牌。

点击右上角即可分享
微信分享提示