How can i access local directory with pyscript?

hello, all.
I’m confused about the way pyscript worked. (specially, writing and reading files.)
I’d appreciate it if you could explain why this happened.

First of all,
I couldn’t import my custom pakages.

I made python code file on a same directory as html file, and i wanted to use my custom pakages, but it didn’t work.
So i tried such a path on my html. All of that were not worked.
/data.py
./data.py
\data.py
.\data.py
\data.py
data.py

I did an experiment to know the directory the pyscript is looking at.

import os

print('start')
print(os.getcwd())

with open('/read_this_text2.txt','wt') as f:
    f.write('hellod')
    print(f.tell())

with open('/read_this_text2.txt','rt') as f:
    text = f.read()
print(text)

I run this simple code with pyscript.
And result is…

I think, pyscript executed my code, created textfile, and read text.
(’/home/pyodide’ … this directory is not on my computer. where was that?)
But, textfile was not on my computer. I searched all the directories but couldn’t find the file.

In case, I changed user name to english, but same thing happened.

I have two questions.

  1. Where is kernel of pyscript? Is that on users computer, or virtual filesystem browser made, or somewhere?
  2. How can i access local directory with pyscript? os.chdir() is not worked.

Thanks for reading my questions.

The first two questions and answers here should help you understand the problem you are facing: Frequently Asked Questions — Version 0.20.0

2 Likes