print(1, 2) prints "1_space_2"

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
kkimdev
Posts: 6
Joined: Thu Feb 08, 2018 5:15 am

print(1, 2) prints "1_space_2"

Post by kkimdev » Fri Jan 04, 2019 9:57 am

Hi, I'm using Numworks port of Micropython https://github.com/numworks/epsilon/ and just noticed print(1, 2) prints "1_space_2" which should be "1 2" instead., mp_builtin_print uses `MP_QSTR__space_` for the separator, which Numeoworks port defines as `Q(_space_)` . I guess original Micropython defined _space_ somewhere else as " "? But I couldn't find it :(

stijn
Posts: 305
Joined: Thu Apr 24, 2014 9:13 am

Re: print(1, 2) prints "1_space_2"

Post by stijn » Fri Jan 04, 2019 10:31 am

For normal micropython the definition is in a file generated by makeqstrdefs.py and makeqstrdata.py during the build, qstrdefs.generated.h, and looks like QDEF(MP_QSTR__space_, (const byte*)"\x85\xb5\x01" " ") (for my windows build, might be different depending on port). This is pulled from the Q( ) in qstrdefs.h which gets special treatment in makeqstrdata.py.

kkimdev
Posts: 6
Joined: Thu Feb 08, 2018 5:15 am

Re: print(1, 2) prints "1_space_2"

Post by kkimdev » Sat Jan 05, 2019 11:54 am

Thanks! I've found it.. I don't understand why it prints differently then lol.... shouldn't normal micropython also print _space_ ? https://github.com/micropython/micropyt ... ins.c#L384

stijn
Posts: 305
Joined: Thu Apr 24, 2014 9:13 am

Re: print(1, 2) prints "1_space_2"

Post by stijn » Sat Jan 05, 2019 4:39 pm

kkimdev wrote:
Sat Jan 05, 2019 11:54 am
shouldn't normal micropython also print _space_ ?
No, because in qstrdefs.generated.h it reads

Code: Select all

QDEF(MP_QSTR__space_ blablabla " ")
and that last string is a space (as put there by the transform in makeqstrdata.py because it has codepoint2name[ord(' ')] = 'space'). So I assume the qstr generation for the port you're referring to does something wrong there.

kkimdev
Posts: 6
Joined: Thu Feb 08, 2018 5:15 am

Re: print(1, 2) prints "1_space_2"

Post by kkimdev » Sat Jan 05, 2019 11:58 pm

Oh I see. Numworks port has the same makeqstrdata.py https://github.com/numworks/epsilon/blo ... strdata.py but somehow it was generating

Code: Select all

QDEF(MP_QSTR__space_, (const byte*)"\xe1\x07" "_space_")
But I think it should be straightforward to debug at this point. Thanks a lot!!

kkimdev
Posts: 6
Joined: Thu Feb 08, 2018 5:15 am

Re: print(1, 2) prints "1_space_2"

Post by kkimdev » Sun Jan 06, 2019 2:50 am

OK so the issue was that, for _space_ we actually need the following two lines and must be ordered in that way.

Code: Select all

Q( )
Q(_space_)

stijn
Posts: 305
Joined: Thu Apr 24, 2014 9:13 am

Re: print(1, 2) prints "1_space_2"

Post by stijn » Sun Jan 06, 2019 9:50 am

Good find!

Post Reply