i've got some code in a big function near the end:
the output from the 2nd print() call is:
i added code
1 2 3 4 5 |
... doc_str = getattr (function, '__doc__' , None ) print ( len (doc_str), 'doc_str =' , repr (doc_str),flush = 1 ) print ( len (doc_str), 'doc_str =' , repr (doc_str[: 150 ]),flush = 1 ) return doc_str |
Output:0 doc_str = ''
in previous versions of the code it was getting data in doc_str
so i put the 1st print() call back in. originally the change was adding len(doc_str),
and [:150]
. now with 2 print calls, the 1st prints out the quoted (by repr()) doc string i expect, but the len(doc_str)
comes out 0
. so what is happening is that after the getattr() call gets the doc string and assigns it to doc_str
and the 1st print() call outputs 0 doc_str = '
followed by over 100 lines of documentation (looks like the correct documentation) then the ending quote from repr(). at this point it is curious how the len() can be 0
with lots of characters there. then the 2nd print() call with the sliced string (originally i added the slicing so as not to have 100+ lines) outputs:Output:0 doc_str = ''
what can cause this weird effect? it's losing data and len()
is just wrong. the caller is getting a null string, too. it should be getting that documentation i see from the 1st print() call (less the quotes that repr() is adding in the print() call).i added code
r = repr(doc_str)
to assign the repr() result to r
then printed the length of r
and got 3079. so repr() got 3077 characters and len() got 0. could this string be internally corrupt? it originally comes from the botocore library which has been working OK for me. this is the first time i am extracting doc strings from its client methods. i don't know if there is any C/binary code in botocore to mess up these stings.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.