documentation is wrong for exec() - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: documentation is wrong for exec() (/thread-20089.html) |
documentation is wrong for exec() - Skaperen - Jul-27-2019 the documentation for exec() says the first argument must be a string or code object and that only the unix style end-of-line is accept. but i have found that it also works with bytes and works with both '\r\n' and '\r' style end of lines. anyone know why? RE: documentation is wrong for exec() - Gribouillis - Jul-27-2019 Skaperen Wrote:the documentation for exec() says the first argument must be a string or code object and that only the unix style end-of-line is acceptDo you have a link to this part of the documentation? RE: documentation is wrong for exec() - Skaperen - Jul-27-2019 no. it's in a PDF. what does your documentation say? RE: documentation is wrong for exec() - perfringo - Jul-27-2019 From python.org: Quote:This function supports dynamic execution of Python code. object must be either a string or a code object. If it is a string, the string is parsed as a suite of Python statements which is then executed (unless a syntax error occurs). RE: documentation is wrong for exec() - Gribouillis - Jul-27-2019 Oh I see, I missed the footnote. Well, Skaperen, can you send us an MCVE where it works unexpectedly with Windows or Mac end of lines? RE: documentation is wrong for exec() - Skaperen - Jul-27-2019 MCVE? i don't know what that means. here is a simple demo:
RE: documentation is wrong for exec() - Gribouillis - Jul-28-2019 My idea is that the footnote is obsolete. You may have discovered a flaw in the official documentation. Now I think it's not our job to find an example of the footnote's claim. It should be included in the documentation. RE: documentation is wrong for exec() - Skaperen - Jul-28-2019 i discovered this because i wanted to see what exception it would actually raise. but the fact that it can just do these things lets me simplify my code. i don't need to decode bytes to strings and i don't need to do '\n'.join(whatever.splitlines()) to be sure i have consistent line endings for code snippets to run in exec().
RE: documentation is wrong for exec() - buran - Jul-28-2019 (Jul-27-2019, 10:56 PM)Skaperen Wrote: MCVE? i don't know what that means.mcve = a minimal, complete and verifiable example https://stackoverflow.com/help/minimal-reproducible-example RE: documentation is wrong for exec() - Skaperen - Jul-28-2019 i knew those words, just not the acronym. |