0
$\begingroup$

Rosanswers logo

Hello I'm a noob at python, I downloaded this github package (turtlesim_hunter) Then when I rosrun I get a syntax error:

knives@knives:~/catkin_ws/src/turtlesim_hunter/src/turtlesim_hunt/Scripts$ rosrun turtlesim_hunt hunt.py
  File "/home/knives/catkin_ws/src/turtlesim_hunter/src/turtlesim_hunt/Scripts/hunt.py", line 151
    print "Found #" + str(huntedTurtles) + " after " + str(finalTime) + " Current Avg: " + str(totalHuntTime / huntedTurtles)
                  ^
SyntaxError: invalid syntax

The issue is at line 151 in the hunt.py script:

https://github.com/tiedyedguy/turtlesim_hunter/blob/master/src/turtlesim_hunt/Scripts/hunt.py

print "Found #" + str(huntedTurtles) + " after " + str(finalTime) + " Current Avg: " + str(totalHuntTime / huntedTurtles)

I don't know whats wrong and I can't google myself to a specific answer, is the issue that this was written with python 3 and I only have python 2.7 installed? I highly doubt this guy has an error in his code since it's working for him:

https://www.youtube.com/watch?v=LywSOGRtFLY


Originally posted by KevinH on ROS Answers with karma: 1 on 2017-12-30

Post score: 0


Original comments

Comment by lucasw on 2018-01-02:
Try commenting out that line (put a # in front of it), and if you want to see what it was printing gradually restore it - just print the huntedTurtles bit and put the hash after but before the plus sign with the rest of it, then move the hash to the right so more and more of the line will print

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Try enclosing your print parameters in brackets, this fixed the problem for me:

print ("Found #" + str(huntedTurtles) + " after " + str(finalTime) + " Current Avg: " + str(totalHuntTime / huntedTurtles))

Hope this helps.


Originally posted by PeteBlackerThe3rd with karma: 9529 on 2018-01-03

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.