Obtaining a function's name

9 views
Skip to first unread message

Harlan Gilbert

unread,
Sep 4, 2022, 12:09:31 PM9/4/22
to Glowscript Users
Bruce,

A minor issue:

The __name__ property returns the function's name in installed Python, but in Glowscript  it returns undefined:

print(abs.__name__)

Best wishes,
Harlan

Harlan Gilbert

unread,
Sep 4, 2022, 12:39:13 PM9/4/22
to Glowscript Users
Also: to obtain an object's properties and methods, Python offers two functions: vars(object) and dir( object ).  In Python, both return extensive lists.
vars is absent in Glowscript and dir returns an empty list. 

print(dir(int))
print(vars(int))

Bruce Sherwood

unread,
Sep 4, 2022, 1:37:04 PM9/4/22
to Glowscript Users
This is of course due to the fact that Web VPython uses the RapydScript-NG transpiler to convert Python code to JavaScript code, to be able to run in the browser. These functions are way too obscure to attempt to deal with them in Web VPython.

I'm very puzzled by the __name__ property. What is the point of getting the name if you have to use the known name to get the name??

Bruce

Harlan Gilbert

unread,
Sep 4, 2022, 1:56:34 PM9/4/22
to glowscri...@googlegroups.com
It's quite useful!!!
For example, here is an extract from code graphing a series of functions.  I want each graph to be titled with the function's name..

functionlist = [linear, abs, quad, poly, sin, tan, exp, sqrt]               #some of these are defined in my code
for f in functionlist:
   gd = graph(title=f.__name__)

It's easy to make a parallel list of names, but it should be noted as an area of incompatibility.:

--

---
You received this message because you are subscribed to a topic in the Google Groups "Glowscript Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/glowscript-users/-7sA8HtUVDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to glowscript-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/glowscript-users/CA%2BWuaScngsFpBkLyJkGcX8orGfJ-NVgyLrFTx3Nce49jRSCtkw%40mail.gmail.com.


--
Harlan Gilbert, Ph.D.
High School Chair and Math, Physics, Computer Science, and Philosophy Teacher
Green Meadow Waldorf High School
Chestnut Ridge, NY 10977
Reply all
Reply to author
Forward
0 new messages