docstring challenge

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Hanilein
Posts: 29
Joined: Thu Jul 12, 2018 11:40 am
Location: Christchurch, New Zealand

docstring challenge

Post by Hanilein » Thu Jul 12, 2018 1:00 pm

Hi, I am running MicroPython on a Pyboard and I am new to Python, but not to programming.
I found online a site explaining the use of DocString and i defined a function 'nonsense' in a module 'clock.py' :
[code]
# file clock.py : Clock Functions
import pyb
def nonsense():
'''test doc string'''
return 'ClapClap'
[/code]
That works fine, but the function does not have that docstring:
[code]
>>> import clock
>>> print(clock.nonsense())
ClapClap
>>> help(clock.nonsense)
object <function nonsense at 0x200035d0> is of type function
>>> print(clock.nonsense)
<function nonsense at 0x200035d0>
[/code]
What am i doing wrong here?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: docstring challenge

Post by kevinkk525 » Thu Jul 12, 2018 4:19 pm

in micropython docstrings are removed to save RAM and flash size, if I remember correctly. I think you can change that with a parameter and build the firmware again, but I don't know where.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Hanilein
Posts: 29
Joined: Thu Jul 12, 2018 11:40 am
Location: Christchurch, New Zealand

Re: docstring challenge

Post by Hanilein » Fri Jul 13, 2018 4:36 am

Thanks, Kevin - can anybody confirm this?
I vaguely recall the very first try to get a docstring somehow worked - or maybe it was an illusion?

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: docstring challenge

Post by loboris » Fri Jul 13, 2018 8:10 am

You can enable docstrings in mpconfig.h ( or mpconfigport.h)

Code: Select all

// Whether to include doc strings (increases RAM usage)
#ifndef MICROPY_ENABLE_DOC_STRING
#define MICROPY_ENABLE_DOC_STRING (0)
#endif

Post Reply