A small question in python

So, I am trying to add the sonar range values to my code. I added the call back function in the same class. My question is, is the method in which I defined it means it’s accessible within the other functions?

So, I added a subscriber, and finally the call back function. and I was just wondering if the range value would be accessible in the camera callback function?

Based on my understanding, it should be. Just wanted to confirm

I try to setup class variables in the init function which also sets their type (a common python PITA).

So in your init you could use
self.sonarId = 0
self.sonarRange = 9.9

(I like to set sonar ranges to some fixed value and not zero so you can see when they change from 0 or not)

I would avoid initial definition of a class member in a callback and prefer setting them up right from the start in init.

You are welcome to mess with python scope experiments and print self.sonarRange from time to time in your main which would answer your question as well.

Disclaimer: I am no python expert by any means but use it because it is very powerful and easy to change on the fly. As you know there are a ba-zillion python info pages on the web.