I'm running into a frustrating problem, pyscript says the directory doesn't exist. But it is. I have a file called "pot1" and pyscript doesn't seem to see it. I have rewritten the directory over 893 times and trying to find the problem, I have the directory written to the file correctly.
<py-script> pot1 = open("C:/Plant Lab/sav/garden/pots/pot1", "r").readline() </py-script>
But I only get this.
Traceback (most recent call last): File "/lib/python3.10/_pyodide/_base.py", line 460, in eval_code .run(globals, locals) File "/lib/python3.10/_pyodide/_base.py", line 306, in run coroutine = eval(self.code, globals, locals) File "<exec>", line 1, in <module> FileNotFoundError: [Errno 44] No such file or directory: 'C:/Plant Lab/sav/garden/pots/pot1'
I tried searching on Google but ended up getting very basic answers like "Did you write the table of contents correctly?" and I didn't know what else to do. I've tried using \ instead of /. Tried to find out what directory it is but CORS won't let me. In the meantime, I'll try again and again.
When using pyscript, the code runs in a virtual file system. If you run
You should get
/home/pyodide
, which is the root directory of this virtual file system. Your folders and files are not directly accessible through this virtual system (this is a limitation of Javascript applications).The easiest way to access data from the file system is to use the
tag to get the file (more info here).If you update the file like this and try to access it, you will still get the error. This is because the fetch method is usually used to load content from a remote server, but in your case you can run a simple python web server by running
python3 -m http.server
Then visit your page http://0.0.0.0:8000/yourfile.html一个>.