pin.__str__() stupid question

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
Pikachu
Posts: 5
Joined: Tue Jul 29, 2014 1:55 pm

pin.__str__() stupid question

Post by Pikachu » Mon Dec 08, 2014 3:17 pm

Hello,

Iam runniging some Micro Python code directy on the pyboard by using the REPL prompt.

Code: Select all

import pyb
x = pyb.Pin(pyb.Pin.board.X1, pyb.Pin.IN)
s = x.__str__()
Im getting the error message:
AttributeError: 'Pin' object has no attribute '__str__'

Sorry for this stupid question, but whats wrong with this code? :roll:

Thanks for your help

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: pin.__str__() stupid question

Post by dhylands » Mon Dec 08, 2014 3:36 pm

Try using str(pin) as a workaround.

User avatar
Pikachu
Posts: 5
Joined: Tue Jul 29, 2014 1:55 pm

Re: pin.__str__() stupid question

Post by Pikachu » Tue Dec 09, 2014 6:40 am

Thanks :D

Another question, is there any possiblity to cast a string (e.g. s = 'A0') to a pin object?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: pin.__str__() stupid question

Post by dhylands » Tue Dec 09, 2014 6:49 am

You can do:

Code: Select all

x = pyb.Pin('A0')
or the equivalent:

Code: Select all

s = 'A0'
x = pyb.Pin('A0')
See the docs: http://docs.micropython.org/en/latest/l ... b.Pin.html

Post Reply