Excercise 2.2 : Pythons Basics for robotics (regarding header files)

In this exercise we are told to create a code so that we call values of distance of obstacles from a function which is there to store the output of the lasers on top of the turtle-bot.

So, I did everything which was told. And the program ran perfectly as well.
But I have a little doubt about the header files which we are supposed to mention every time.
So when writing this small code why the header files were not mentioned. How come the program got executed. How did the computer know it is a python program?

I Remember while creating a bash script we write : #!/bin/bash

P.S : the first line of code was like this
from robot_control_class import RobotControl

Hi @ambujchoudha5796,

The code you are told to write is:

from robot_control_class import RobotControl

rc = RobotControl()

a = rc.get_laser(360)

print ("The distance measured is: ", a) 

The reason why you didn’t have to import any header messages is because the import happens on the robot_control_class file.

You can confirm that with:

head /home/simulations/public_sim_ws/src/all/ros_basics_examples/python_course_class/robot_control_class.py

With regards to “how the system knows it is a python program?”, there are two ways to tell the system that it is a python program.
You can either put the code below in the first line of the script:

#! /usr/bin/env python

Or you can just type python script_name.py, which is what we are going as we can see on the instructions when tell us to type:

python pyscript1.py

In this case, we are already calling python directly. The python interpreter then just parses the pyscript1.py file.

Please let us know in case you need more clarification.


Thank you @ralves for helping me out! :slight_smile:

Happy Quarantine!

1 Like