NewComer's question about standard lib usage, like os.listdir and os.popen

31 views
Skip to first unread message

Yijun Zhu

unread,
Oct 3, 2017, 11:15:15 AM10/3/17
to brython
Hello Brython experts

i am the newcomer for Brython, so i have some "stupid" question related to the usage of Brython's standard lib like OS

i wish i could list my local directory, then i could do some handling, like:

.....

<script type="text/javascript" src="brython.js"></script>

<script type="text/javascript" src="brython_stdlib.js"></script> 

</head>

<body onload="brython()">

<script type="text/python">

from browser import document, alert

from browser.html import A,B,DIV

import os,re


fileList = os.listdir(os.getcwd())

names = str(fileList)

alert(names)


fileNames = os.popen("ls /home/user/folder").read()

alert(filenames)


#################


nothing popup by the vars,which seems Lib os did not work this style

but, some os operation is ok, like os.getcwd()


any comments are welcome!!


thanks

/Yijun

kikocorreoso

unread,
Oct 3, 2017, 12:06:16 PM10/3/17
to bry...@googlegroups.com, Yijun Zhu


On 03/10/17 17:15, Yijun Zhu wrote:
Hello Brython experts

i am the newcomer for Brython, so i have some "stupid" question related to the usage of Brython's standard lib like OS

i wish i could list my local directory, then i could do some handling, like:

It is client-side javascript in the end so you are limited by the client. It is this way for safety reasons.

If you want to list the files in a dir you could connect to the backend (the computer where you want to list the files), let the backend (python, node, java, c#,...) perform the operations you want on the system and then send the results to the client-side.

User -> Browser -> Brython -> Backend (Python?) -> Brython -> Browser -> User

I hope it helps.

.....

<script type="text/javascript" src="brython.js"></script>

<script type="text/javascript" src="brython_stdlib.js"></script> 

</head>

<body onload="brython()">

<script type="text/python">

from browser import document, alert

from browser.html import A,B,DIV

import os,re


fileList = os.listdir(os.getcwd())

names = str(fileList)

alert(names)


fileNames = os.popen("ls /home/user/folder").read()

alert(filenames)


#################


nothing popup by the vars,which seems Lib os did not work this style

but, some os operation is ok, like os.getcwd()


any comments are welcome!!


thanks

/Yijun

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/24e61bb6-9037-4d47-b152-7aaa304f00f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yijun Zhu

unread,
Oct 3, 2017, 1:05:04 PM10/3/17
to brython
thanks kiko for your help

could you show me the simple example of "backend perform the operations  and then send the results to the client-side."

like backend execute : os.getcwd() for the local path,
send the results to the client-side: send the local path to client-side
thanks,
/Yijun
Reply all
Reply to author
Forward
0 new messages