git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using exec with embedded python interpreter 3.7


Eko palypse wrote:

> I've already sent this through mail yesterday but it doesn't appear here,
> maybe because of the help word in the content. Please execute in case it
> appears a second time.
> 
> 
> Hello,
> I'm creating a notepad++ plugin which hosts an embedded python interpreter
> by using cffi to build the dll. So far so good. One obstacle I've found is
> that I'm not able to use exec(help(object)) in order to get the wanted
> info from the object.
> 
> The error I get is:
> 
> Traceback (most recent call last):
>   File "<init code for 'Python3Script'>", line 131, in run_code
>   File "<string>", line 1, in <module>
>   File "D:\...\Python\Python37_64\Lib\_sitebuiltins.py", line 103, in
>   __call__
>     return pydoc.help(*args, **kwds)
>   File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1895, in __call__
>     self.help(request)
>   File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1954, in help
>     else: doc(request, 'Help on %s:', output=self._output)
>   File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1674, in doc
>     pager(render_doc(thing, title, forceload))
>   File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1451, in pager
>     pager(text)
>   File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1576, in plainpager
>     sys.stdout.write(plain(_escape_stdout(text)))
>   File "D:\...\Python\Python37_64\Lib\pydoc.py", line 1528, in
>   _escape_stdout
>     return text.encode(encoding, 'backslashreplace').decode(encoding)
> TypeError: encode() argument 1 must be str, not method

The traceback suggests that sys.stdout was replaced with a custom object 
that has a method stdout.encoding() rather than the expected stdout.encoding  
attribute of type str.

> If I encase the object with quotes then I do get the info that no
> documentation is found for that object.
> 
> 1. It doesn't feel right to encase the object with quotes. I don't have to
> do this using the standard python interpreter shell. What did I miss?
> 
> 2. If it is needed to use the encased way, why don't it show the help
> info? The object class contains the module, class and functions doc
> strings, what did I miss here?
> 
> Thank you
> Eren