Reputation: 47
I'm currently trying to understand Pyth. I know Python quite well, but I don't get Pyth sometimes.
My code:
DhNKlNFzrKZaY@Nz;Y;hQ
It's just a basic script for reversing string, and traceback gives me ValueError,
ValueError: malformed node or string: <_ast.Name object at 0x7ff2fde45c18>
Despite my Python knowledge I have no idea what does this error mean. Can you show me where is this error coming from?
Upvotes: 3
Views: 454
Reputation: 4795
I assume you are getting an error like this one here:
Traceback (most recent call last):
File "pyth.py", line 771, in <module>
File "<string>", line 3, in <module>
File "/app/macros.py", line 691, in eval_input
File "/app/.heroku/python/lib/python3.4/ast.py", line 84, in literal_eval
File "/app/.heroku/python/lib/python3.4/ast.py", line 83, in _convert
ValueError: malformed node or string: <_ast.Name object at 0x7fac26eb2b70>
First off, you use z
and Q
inconsistently. With your current code, input should have been taken like this instead:
"abcd"
abcd
When Q
is used in a Pyth program, z
implicitly jumps to the next line of input, it just skips whatever has been inputted before using Q
. Instead, just use:
DhNKlNFzrKZaY@Nz;Y;hz
And the errors should go away.
I am not sure why you would want to perform string reversal that way, though. I use _z
if the input is not quoted and _
alone otherwise, since Q
is implicit at the end of any Pyth program.
Upvotes: 9