Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

Extend console.log and js object str on py3

Open SpencerPark opened this issue 7 years ago • 1 comments

Another small PR but small PR's get merged quicker :)

This one prints all arguments passed to console.log and also makes __unicode__ work as expected in py3. repr still used __repr__ but str uses __str__ (or __unicode__ on py2) so when printing objects we get the expected result (strings without quotes).

Also now supports calling console.log with no arguments to print a blank line.

console.log('test:', 10);
console.log();
from js2py.pyjs import *
# setting scope
var = Scope( JS_BUILTINS )
set_global_object(var)

# Code follows:
var.registers([])
var.get(u'console').callprop(u'log', Js(u'test:'), Js(10.0))
var.get(u'console').callprop(u'log')
pass

SpencerPark avatar May 01 '19 21:05 SpencerPark

Woops, I guess the print function wasn't being imported. With a single argument it is still the keyword with a single option wrapped in extra parentheses. I'll fix that. Glad you've got ci setup :)

SpencerPark avatar May 02 '19 15:05 SpencerPark