Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to inherit? #44

Closed
sophiekovalevsky opened this issue May 3, 2016 · 3 comments
Closed

How to inherit? #44

sophiekovalevsky opened this issue May 3, 2016 · 3 comments

Comments

@sophiekovalevsky
Copy link

sophiekovalevsky commented May 3, 2016

I'm trying to inherit spidev library to a custom class. I'm using python2.

This is the code that I'm using:
self.spi = spidev.SpiDev()
self.spi.open(bus,CS)
self.spi.mode = 0
self.spi.lsbfirst = False
self.spi.max_speed_hz = speed

And its tell me that global name 'spi' is not defined. Any suggestions?

@sophiekovalevsky
Copy link
Author

I finally set up, using:
class Classname(spidev.SpiDev):

@luxedo
Copy link
Contributor

luxedo commented May 3, 2016

Hello!
I belive that the best way to inherit is in the class definition

import spidev
class MySpiDev(spidev.SpiDev):
    def __init__(self, *args, **kwargs):
        super(MySpiDev, self).__init__(*args, **kwargs) # python 2
        super().__init__(*args, **kwargs) # python 3
        self.open(bus, CS)
        self.mode = 0
        ...

@sophiekovalevsky
Copy link
Author

Thanks a lot for your feedback :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants