[Kinda SOLVED] String Methods missing

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
yeyeto2788
Posts: 28
Joined: Wed Mar 30, 2016 4:09 pm

[Kinda SOLVED] String Methods missing

Post by yeyeto2788 » Mon Dec 11, 2017 2:33 pm

Hello guys!

Does anyone of you has use strings methods on your code?

I'm trying to use the following:

Code: Select all

str.center(width, fillchar)
str.ljust(width, fillchar)
str.rjust(width, fillchar)
str.title()
and none of those worked :( here you have the output from the REPL:

Code: Select all

MicroPython v1.9.2-8-gbf8f45cf on 2017-08-23; ESP module with ESP8266
Type "help()" for more information.
>>> a = "pepito"
>>> a.center(10,"*")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'center'
>>> a.rjust(10,"*")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'rjust'
>>> a.ljust(10,"*")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'ljust'
>>> a.title()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'title'
>>> b = a.title()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'title'
>>>

Note: I have looked at the documentation but no reference to those.
http://docs.micropython.org/en/latest/p ... ltins.html

Regards.


UPDATE

I got it to work with

Code: Select all

.format
as follow:

Code: Select all

a = "hola"
print('{:*^10}'.format(a))

User avatar
Roberthh
Posts: 1046
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: [Kinda SOLVED] String Methods missing

Post by Roberthh » Mon Dec 11, 2017 3:08 pm

I got it to work with

.format
That's indeed the proposed method, to keep MicroPython micro. There were discussions already around that topic, if not in the forum, then in the github repository.

pfalcon
Posts: 1060
Joined: Fri Feb 28, 2014 2:05 pm

Re: [Kinda SOLVED] String Methods missing

Post by pfalcon » Sat Dec 16, 2017 8:48 am

But the main source of information is the documentation: http://docs.micropython.org/en/latest/p ... mplemented

Can be found easily by searching docs by "ljust": http://docs.micropython.org/en/latest/p ... ea=default
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib

Post Reply