Welcome to PyPy.js!
>>> import os
>>> os.listdir('/')
['tmp', 'home', 'dev', 'lib']
>>> f = open('/what', 'w')
>>> f.write('hey')
>>> f.close()
>>> os.listdir('/')
['tmp', 'home', 'dev', 'lib', 'what']
>>> open('/what').read()
'hey'
What is in the stack that makes that work?PyPy.js: Python in the web browser
61–70 of 129 posts
Re: PyPy.js: Python in the web browser
#62Re: PyPy.js: Python in the web browser
#63I'm curious about the virtual filesystem: Welcome to PyPy.js! >>> import os >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib'] >>> f = open('/what', 'w') >>> f.write('hey') >>> f.close() >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib', 'what'] >>> open('/what').read() 'hey' What is in the stack that makes that work?
Re: PyPy.js: Python in the web browser
#64Great project. My team used it for a live-coding Python notebook: https://github.com/inkandswitch/livebook#readme To my surprise it was faster than Jupyter / CPython for some tasks (e.g. loading and parsing large CSVs).
Re: PyPy.js: Python in the web browser
#65I'm curious about the virtual filesystem: Welcome to PyPy.js! >>> import os >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib'] >>> f = open('/what', 'w') >>> f.write('hey') >>> f.close() >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib', 'what'] >>> open('/what').read() 'hey' What is in the stack that makes that work?
Re: PyPy.js: Python in the web browser
#66I'm curious about the virtual filesystem: Welcome to PyPy.js! >>> import os >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib'] >>> f = open('/what', 'w') >>> f.write('hey') >>> f.close() >>> os.listdir('/') ['tmp', 'home', 'dev', 'lib', 'what'] >>> open('/what').read() 'hey' What is in the stack that makes that work?
The Emscripten File System API, "The API is inspired by the Linux/POSIX File System API, with each presenting a very similar interface." https://kripken.github.io/emscripten-site/docs/api_reference...
Re: PyPy.js: Python in the web browser
#67Didn't we decide a long while back that fully featured programming languages were dangerous in the browser, especially if they could do disk I/O? Even if sandboxed? A la Java Applets and Adobe Flash? import os for subdir, dirs, files in os.walk('./'): for file in files: print file os.remove(file) Perhaps the environment is "fake", and these files don't really exist, even in some sandbox... otherwise, seems like this…
This is Javascript, not real Python. If you're so afraid that this is dangerous, why do you post malicious code? And if you're so clever to post that code, why don't you try similar code to see if it really has access to your files? import os os.listdir('/') The answer, by the way, is no.
That's not malicious code... it removes files from a sandbox... you can refresh the page and see for yourself.
> And if you're so clever to post that code
There's no need to be rude... there's an honest question and lack of understanding in my post - educate me, don't talk down to me.
> why don't you try similar code to see if it really has access to your files
The question was if someone could break out of a sandbox, such as with Java Applets and Adobe Flash. I have no idea how to do that - I'm not a security specialist, nor some sort of hacker guy.
> The answer, by the way, is no.
From the sandbox and using the standard `import os`, ya, you're right. The question, again, is what if someone got outside the sandbox?
Re: PyPy.js: Python in the web browser
#68Earlier quoted context omitted.
I don't know about PyPy.js specifically, but most systems like this provide a virtual filesystem that maps back to things like indexedDB and localstorage which are browser APIs. There is no way that pypy.js is able to access local files on your machine outside of the browser sandbox.
I bet there's a few cheeky hackers around the world who may disagree with that statement. Always assume it's broken.
Re: PyPy.js: Python in the web browser
#69Earlier quoted context omitted.
This is Javascript, not real Python. If you're so afraid that this is dangerous, why do you post malicious code? And if you're so clever to post that code, why don't you try similar code to see if it really has access to your files? import os os.listdir('/') The answer, by the way, is no.
> If you're so afraid that this is dangerous, why do you post malicious code? That's not malicious code... it removes files from a sandbox... you can refresh the page and see for yourself. > And if you're so clever to post that code There's no need to be rude... there's an honest question and lack of understanding in my post - educate me, don't talk down to me. > why don't you try similar code to see if it really has…
Re: PyPy.js: Python in the web browser
#70Pity it's not Python3.
Yeah weird. I would expect Python2 to be dying off more by now. Wonder if we're headed to an environment where there's essentially 2 separate languages as Python 3 continues to change and grow?
I have no idea why would a project of this caliber would start by using Python 2 instead of Python 3.
Edit: When I started reading about GCF, all docs said I could only use Python 2. Later I found that they seem to be on the way to change this. But still, I was very surprised that Python 2 was even an option to begin with.