2 added 6 characters in body
source | link

if __name__ == '__main__': doesn't matter at here (in the second code), also you could run your code without it like here:

Second code:

.
.
.
# MAIN
try:
    process()
except rospy.ROSInterruptException:
    pass

i.e. when you don't want your code to run when it imported in another python code, you should use if __name__ == '__main__':

More information.


The main difference between First code and Second code is that the Second code used the rospy.spin() method which is a built-in ROS loop that triggers the publisherpublisher and subscribersubscriber in another thread, so you wouldn't need to an inner whilewhile in your code like the First example.

Relevant Question.

if __name__ == '__main__': doesn't matter at here (in the second code), also you could run your code without it like here:

Second code:

.
.
.
# MAIN
try:
    process()
except rospy.ROSInterruptException:
    pass

i.e. when you don't want your code to run when it imported in another python code, you should use if __name__ == '__main__':

More information.


The main difference between First code and Second code is that the Second code used the rospy.spin() method which is a built-in ROS loop that triggers the publisher and subscriber in another thread, so you wouldn't need to an inner while in your code like the First example.

Relevant Question.

if __name__ == '__main__': doesn't matter at here (in the second code), also you could run your code without it like here:

Second code:

.
.
.
# MAIN
try:
    process()
except rospy.ROSInterruptException:
    pass

i.e. when you don't want your code to run when it imported in another python code, you should use if __name__ == '__main__':

More information.


The main difference between First code and Second code is that the Second code used the rospy.spin() method which is a built-in ROS loop that triggers the publisher and subscriber in another thread, so you wouldn't need to an inner while in your code like the First example.

Relevant Question.

1
source | link

if __name__ == '__main__': doesn't matter at here (in the second code), also you could run your code without it like here:

Second code:

.
.
.
# MAIN
try:
    process()
except rospy.ROSInterruptException:
    pass

i.e. when you don't want your code to run when it imported in another python code, you should use if __name__ == '__main__':

More information.


The main difference between First code and Second code is that the Second code used the rospy.spin() method which is a built-in ROS loop that triggers the publisher and subscriber in another thread, so you wouldn't need to an inner while in your code like the First example.

Relevant Question.