Comments (5)
[deleted comment]
from pyv8.
I'm not sure what's your real problems, could you give me some example or unit
test code?
In fact, _PyV8.JSArray support the python Sequence Protocol. It means, you
could
use its predefined methods such as __iter__, __len__ or __getitem__ etc.
>>> list(ctxt.eval("new Array(1, 2, 3)"))
[1, 2, 3]
>>>
On the other hand, javascript doesn't have build-in dictionary, even you could
create object with JSON syntax, such as
>>> r = ctxt.eval("var r = {'a' : 1, 'b' : 2}; r ")
>>> r
<_PyV8.JSObject object at 0x00AE9170>
>>> dir(r)
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__float__', '__ge
tattr__', '__getattribute__', '__hash__', '__init__', '__int__', '__js__', '__me
mbers__', '__module__', '__ne__', '__new__', '__nonzero__', '__reduce__', '__red
uce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'a', 'b']
>>> r.a
1
>>> r.b
2
Original comment by [email protected]
on 5 May 2009 at 4:02
from pyv8.
[deleted comment]
from pyv8.
hi flier,
thanks for pointing this out. it wasn't clear for that i can use the builtin
__members__ to get all attributes to
iterate over.
i've written a small function that converts a cx.eval()-result into a python
dict. maybe someone needs this
too.
cheers marc
Original comment by [email protected]
on 5 May 2009 at 11:04
Attachments:
from pyv8.
Thanks, I have merged your contribution in pyv8.py
http://code.google.com/p/pyv8/source/detail?r=123
on the other hand, I add some code to simulate a dict in JSObject class
def testDict(self):
import UserDict
with JSContext() as ctxt:
obj = ctxt.eval("var r = { 'a' : 1, 'b' : 2 }; r")
self.assertEqual(1, obj.a)
self.assertEqual(2, obj.b)
self.assertEqual({ 'a' : 1, 'b' : 2 }, dict(obj))
self.assertEqual({ 'a': 1,
'b': [1, 2, 3],
'c': { 'str' : 'goofy',
'float' : 1.234,
'obj' : { 'name': 'john doe' }},
'd': True,
'e': None },
convert(ctxt.eval("""var x =
{ a: 1,
b: [1, 2, 3],
c: { str: 'goofy',
float: 1.234,
obj: { name: 'john doe' }},
d: true,
e: null }; x""")))
Original comment by [email protected]
on 6 May 2009 at 3:45
- Changed state: Fixed
from pyv8.
Related Issues (20)
- LookupError: unknown encoding: HOT 5
- New function to modify the maximum call stack size limit HOT 4
- Can't override eval method when inheriting JSClass HOT 2
- Compilation error HOT 7
- Compilation issue on Ubuntu 13.10 - no matching function for call to ‘CAstVisitor::InitializeAstVisitor(v8::internal::Isolate*)’ HOT 2
- Symbol not found: __ZSt20__throw_length_errorPKc HOT 2
- Builds HOT 5
- Garbage Collector not working HOT 8
- Memory leak with evaluating pure JS HOT 3
- How to load contents of alert screen ?
- Update version on PyPI
- error: 'CLASSIC_MODE' is not a member of 'v8i' v8 API change ?
- REVISION
- AST can't visit object properties: No to_python (by-value) converter found for C++ type: v8::internal::ObjectLiteralProperty*
- src/Context.h:66:114: error: no member named 'HasOutOfMemoryException' in 'v8::Context'
- Help !!
- Precompiled for Debain x64 HOT 1
- Failed to pip install/build under linux x64 — lot of errors in src/Wrapper.cpp HOT 1
- segfault
- compile failed with error code 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyv8.