I am having problems accessing a variable from one class to another.

class Player(pygame.sprite.Sprite):
    
    def rotateShip(self, rotAmt):
        
        radians = self.rotation * math.pi / 180

I am trying to use the variable radians from class Player to another class. radians only exists in 'rotateShip'.

Thanks for your help in advance.

Since radians is only self.rotations converted to radians, it would be easier to make it a property

class Player(pygame.sprite.Sprite):
    
    def rotateShip(self, rotAmt):
        # here use self.radians

    @property
    def radians(self):
        return self.rotation * math.pi / 180

In other classes, use player.radians . In this case, you may consider renaming player.rotation to player.degrees.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.