如何在没有Web服务器的情况下将可变数据从Python传输到Javascript? [英] How to transfer variable data from Python to Javascript without a web server?

查看:75
本文介绍了如何在没有Web服务器的情况下将可变数据从Python传输到Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自动生成本地HTML文件,并且我需要的所有相关数据都在Python脚本中。如果没有Web服务器,我不知道如何继续,因为否则我认为AJAX / json解决方案是可能的。

基本上在python中,我有一些列表和字典对象,我需要使用它们来创建使用javascript和HTML的图形。我有一个解决方案(真的很吸引人)是从字面上使用字符串在Python中编写HTML / JS,然后保存到文件中。



我还能在这里做什么?我很确定Javascript没有文件I / O功能。



谢谢。

解决方案

你只需要将你在python代码中的数据转换成你的javascript可读的表单,对吧?

为什么不只是取数据结构,将其转换为JSON,然后编写一个 .js 文件,使您的 .html 文件包含只需 var data = {json:object here};


I'm working on automatically generating a local HTML file, and all the relevant data that I need is in a Python script. Without a web server in place, I'm not sure how to proceed, because otherwise I think an AJAX/json solution would be possible.

Basically in python I have a few list and dictionary objects that I need to use to create graphs using javascript and HTML. One solution I have (which really sucks) is to literally write HTML/JS from within Python using strings, and then save to a file.

What else could I do here? I'm pretty sure Javascript doesn't have file I/O capabilities.

Thanks.

解决方案

You just need to get the data you have in your python code into a form readable by your javascript, right?

Why not just take the data structure, convert it to JSON, and then write a .js file that your .html file includes that is simply var data = { json: "object here" };

这篇关于如何在没有Web服务器的情况下将可变数据从Python传输到Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆