Simplest way to eval python code

103 views
Skip to first unread message

Yehonathan Sharvit

unread,
Aug 14, 2016, 7:22:17 AM8/14/16
to Skulpt
What is the simplest way to eval python code in the browser with Skulpt?

I'd like to evaluate subsequent python code snippets and I need the function defined in a snippet to be accessible by subsequent snippets.

For instance:

snippet 1:
foo = lambda n: n + 2
print(foo(3))

snippet 2:
print(foo(5))

Yehonathan Sharvit

unread,
Aug 24, 2016, 7:18:41 AM8/24/16
to Skulpt
Could anybody help me on this issue?

Brad Miller

unread,
Aug 24, 2016, 12:08:23 PM8/24/16
to sku...@googlegroups.com
Skulpt is not designed to remember things from previous runs.  If you want it to know about foo in another run then you will need to include that in the code you hand over to importMainWithBody.

Bradley Miller, PhD
Professor, Dept. Chair, Computer Science
Luther College
Founder, Runestone Interactive
Blog: A Reputable Journal

--

---
You received this message because you are subscribed to the Google Groups "Skulpt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skulpt+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yehonathan Sharvit

unread,
Aug 24, 2016, 12:27:46 PM8/24/16
to sku...@googlegroups.com
Is there a way to set a global variable to some global object and get its value in subsequent runs, in the sam  browser instance?

Yehonathan Sharvit

unread,
Sep 2, 2016, 1:55:51 AM9/2/16
to Skulpt
Someone could help with this topic?
I'm looking for a way to set a global variable to some global object and get its value in subsequent runs, in the same  browser instance.



On Wednesday, 24 August 2016 19:27:46 UTC+3, Yehonathan Sharvit wrote:
Is there a way to set a global variable to some global object and get its value in subsequent runs, in the sam  browser instance?


On Wed, 24 Aug 2016 at 19:08 Brad Miller <mill...@luther.edu> wrote:
Skulpt is not designed to remember things from previous runs.  If you want it to know about foo in another run then you will need to include that in the code you hand over to importMainWithBody.

Bradley Miller, PhD
Professor, Dept. Chair, Computer Science
Luther College
Founder, Runestone Interactive
Blog: A Reputable Journal
On Wed, Aug 24, 2016 at 6:18 AM, Yehonathan Sharvit <vie...@gmail.com> wrote:
Could anybody help me on this issue?

On Sunday, 14 August 2016 14:22:17 UTC+3, Yehonathan Sharvit wrote:
What is the simplest way to eval python code in the browser with Skulpt?

I'd like to evaluate subsequent python code snippets and I need the function defined in a snippet to be accessible by subsequent snippets.

For instance:

snippet 1:
foo = lambda n: n + 2
print(foo(3))

snippet 2:
print(foo(5))

--

---
You received this message because you are subscribed to the Google Groups "Skulpt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skulpt+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups "Skulpt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skulpt+unsubscribe@googlegroups.com.

Michael Cimino

unread,
Sep 3, 2016, 1:08:43 AM9/3/16
to Skulpt
I haven't tried it using the latest version of Skulpt ... but in the older version of Skulpt (the one used on www.codeskulptor.org), anything stored in Sk.builtins is not cleared between runs and remains available during subsequent runs.

For example, if I run the following python code: 
def foo(x): return "foo"+str(x)+"bar"
Then Sk.globals['foo'] will be a reference to the JavaScript version of the foo function. If I then run (in the JavaScript console, for example) Sk.builtins.foo = Sk.globals['foo'] then in subsequent runs, foo will be a "builtin" function ... and therefore work even though it wasn't defined in the current run.

You'd have to be careful not to overwrite any of the actual "builtin" functions ... but this might be a way for your functions to remain persistent ... or to be defined "outside" the current run.

I hope that helps.
To unsubscribe from this group and stop receiving emails from it, send an email to skulpt+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to the Google Groups "Skulpt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skulpt+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages