Page 1 of 1

docstring challenge

Posted: Thu Jul 12, 2018 1:00 pm
by Hanilein
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?

Re: docstring challenge

Posted: Thu Jul 12, 2018 4:19 pm
by kevinkk525
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.

Re: docstring challenge

Posted: Fri Jul 13, 2018 4:36 am
by Hanilein
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?

Re: docstring challenge

Posted: Fri Jul 13, 2018 8:10 am
by loboris
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