-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with join method #51
Comments
I think you meant: |
To expand a bit: in JS you can add a list and a string (sigh) and the result will be a string. The |
Yes that code would have been better. Both work in python though. Thanks for the explanation. It still seems like an issue with pscript to me. Regardless of funky js conversions, the behavior is different from python and will surprise people. How about mentioning it in the docs under Caveats? To avoid adding list + str because it =str in pscript instead of =list in python. |
Well in Python you cannot add a list or a string: you'd get error. So it's not surprising that it actually works, which I think is the JavaScript shining through section. |
We're talking about two different things. 🙂
My code does += while you're talking about straight +. list += str does in
fact work.
In cpython 3.8:
>> l = []
>> l += 'abc'
>> l
['a', 'b', 'c']
You're correct that straight + doesn't work:
>> [] + 'abc'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "str") to list
It's very odd that += works when + doesn't, but that's cpython behavior.
Almost as weird as adding each character as a separate list element. But
that's python. 🤷♂️
My point is that it should be documented somewhere that += has
different behavior in pscript. You know better than me where that goes.
I haven't tested list + str in pscript. If that results in a string, ok.
As you said, that's a case where javascript "works"... if you consider that
working behavior. 😉
…On Sat, Jan 2, 2021 at 8:28 PM Almar Klein ***@***.***> wrote:
Well in Python you cannot add a list or a string: you'd get error. So it's
not surprising that it actually works, which I think is the *JavaScript
shining through* section.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#51 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIKNAOFMLPS6FGVSCQQPQNLSX5XV7ANCNFSM4VIG4WWA>
.
|
I think I was not really aware that you could do In that case, yes, we should document this. |
done |
Found what seems to be a pscript bug. My code has the following convenience function:
Running this code gives the following error:
Which traces to this bit of transpiled code in myapp.js (line nums shown):
Not sure what the problem is. What I do notice:
My python code is valid and works in cpython. It should work in pscript. Not sure why it doesn't.
I did find a workaround for pscript. Changing the inner loop from += to append fixes the problem with pscript. Which is better practice anyway, since list += string adds each character as a separate list item (this is very old code, prob >10 years). So I did "solve" it. But the original code should still work, even if suboptimal. Seems like a bug in pscript.
The text was updated successfully, but these errors were encountered: