Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error: "self" is not defined error on VSCode on Ubuntu

I’m following a tutorial on understanding writing python publisher in ROS2. This is an example that I’m creating. The code does not seem to have any errors but in vscode, the self word is underlined in red and when I hover the mouse it shows that "self" is not defined. How can I resolve this issue in vscode?

I will add the code here

#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
 
from example_interfaces.msg import String
 
class RobotNewsStationNode(Node):   #modify name
   def __init__(self):
       super().__init__("robot_news_station")  #modify name
 
       self.publisher_ = self.create_publisher(String, "robot_news", 10)
 
 
   def publish_news(self):
       msg = String()
       msg.data = "Hello"
       self.publisher_.publish(msg)
 
      
def main(args=None):
   rclpy.init(args=args)
   node = RobotNewsStationNode()   #modify name
   rclpy.spin(node)
   rclpy.shutdown()
  
if __name__ == "__main__":
   main()

This is the code error im having in vscode
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As the error mentions, you are most likely mixing spaces/tabs.

Try delete all indentation untill that line, then use "tab" to indent your code, and be consistent about it i.e dont mix tabs and space.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading