Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't understand the error traceback gives me

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?

like image 231
XaMi Avatar asked Jan 17 '26 05:01

XaMi


1 Answers

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.

like image 186
Mr. Xcoder Avatar answered Jan 19 '26 19:01

Mr. Xcoder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!