ure.sub not available in v1.10?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

ure.sub not available in v1.10?

Post by ProudPagan » Fri Apr 12, 2019 9:02 am

Hi,

I am developing my MicroPython code on Windows and I see an error when trying to use ure.sub ...

However, the docs say this should be available.

D:\micropython.exe
MicroPython v1.10-278-g673e154df on 2019-04-12; win32 version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import ure
>>> xx="a simple test"
>>> ure.sub('^a', '', xx)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'sub'

andymouse
Posts: 12
Joined: Sat Apr 06, 2019 7:05 pm

Re: ure.sub not available in v1.10?

Post by andymouse » Fri Apr 12, 2019 10:20 am

Hi,
I just typed this does it help as I'm just starting out ?

>>> import ure
>>> help(ure)
object <module 'ure'> is of type module
__name__ -- ure
compile -- <function>
match -- <function>
search -- <function>
sub -- <function>
DEBUG -- 4096
>>>
Andy

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: ure.sub not available in v1.10?

Post by ProudPagan » Fri Apr 12, 2019 3:55 pm

I get this:

>>> help (ure)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'help' isn't defined
>>>

I seem to be missing something.

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

Re: ure.sub not available in v1.10?

Post by Roberthh » Sat Apr 13, 2019 6:11 am

The Windows version of MicroPython is somewhat limited. For whatever reason the help module is not included. Other modules may be missing too. Did you build that version yourself, or where did you get that from

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: ure.sub not available in v1.10?

Post by ProudPagan » Sat Apr 13, 2019 6:31 am

I compiled MicroPython from the Github sources at:
https://github.com/micropython/micropyt ... ts/windows

cross compiled for Windows using Ubuntu sub-system.

Thanks.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

I can't explain this

Post by pythoncoder » Sat Apr 13, 2019 7:07 am

This is an aspect of MicroPython that I find baffling, despite nearly 5 years involvement.
tl;dr the availability of features is often in inverse proportion to the capabilities of the hardware.

On the Unix build:

Code: Select all

>>> dir(ure)
['__class__', '__name__', 'DEBUG', 'compile', 'match', 'search']
>>> 
On a Pyboard D:

Code: Select all

>>> dir(ure)
['__class__', '__name__', 'DEBUG', 'compile', 'match', 'search', 'sub']
>>> 
On an ESP8266:

Code: Select all

>>> dir(ure)
['__class__', '__name__', 'DEBUG', 'compile', 'match', 'search', 'sub']
>>> 
I could understand if ure.sub were omitted on a resource constrained platform like ESP8266. The converse is true. It (and other features) are left out on the platforms with effectively unlimited resources: PC's. Can anyone explain this?
Peter Hinch
Index to my micropython libraries.

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

Re: ure.sub not available in v1.10?

Post by Roberthh » Sat Apr 13, 2019 12:20 pm

I compiled a version of micropython for Windows which includes ure.sub(9 and help(). You'll find it here: https://github.com/robert-hh/Shared-Stuff
And yes, it's strange that ure.sub is not included into all versions, when ist is present in the version with the strongest memory constrainst

ProudPagan
Posts: 35
Joined: Fri Apr 12, 2019 8:55 am

Re: ure.sub not available in v1.10?

Post by ProudPagan » Sat Apr 13, 2019 12:35 pm

Thanks!

It works. I am curious how you compiled this.

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

Re: ure.sub not available in v1.10?

Post by Roberthh » Sat Apr 13, 2019 2:02 pm

I used MINGW for that (https://mingw-w64.org/doku.php). No magic. Just install MINGW on Windows, download the repository and run make. I had to adapt mpconfigport.h in microypthon/ports/windows to enable these features along the line of micropython/ports/esp8266 or the other ports.

Post Reply