I want to ask how to make py-script
not error when using the json package
#2280
Answered
by
WebReflection
Rohamunira
asked this question in
Q&A
-
Currently I'm using py-script with the json package. this is are view from , but when i click the button with id from pyscript import display, document, when
import json
@when("click", selector = "#add")
def add():
try:
open("stored_data/stored.json", "a")
except: pass
with open("stored_data/stored.json", "rt") as f:
stored_data = json.load(f)
note_text = document.querySelector("#input_note").value
if note_text not in stored_data["note"]:
stored_data["note"].append("hello world")
with open("stored_data/stored.json", "wt") as f:
json.dump(stored_data, f, indent = 4) |
Beta Was this translation helpful? Give feedback.
Answered by
WebReflection
Feb 5, 2025
Replies: 1 comment 1 reply
-
the file needs to be fetched into the virtual file system, hence via a config, or it won't be there: https://docs.pyscript.net/2024.11.1/user-guide/configuration/#files |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Rohamunira
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the file needs to be fetched into the virtual file system, hence via a config, or it won't be there: https://docs.pyscript.net/2024.11.1/user-guide/configuration/#files