Triple quoted string in exec function ?

John Machin sjmachin at lexicon.net
Tue Dec 30 20:45:03 EST 2008


On Dec 31, 8:34 am, Steve Holden <st... at holdenweb.com> wrote:
> Stef Mientki wrote:
> > ibpe... at gmail.com wrote:
> >> On Dec 30, 2:48 pm, Steve Holden <st... at holdenweb.com> wrote:
>
> >>> Stef Mientki wrote:
>
> >>>> hello,
> >>>>       I'm running scripts, with the execute function (Python 2.5),
> >>>> and it seems that triple quoted strings are not allowed.
> >>>>       Is there a workaround,
> >>>> or is this a fundamental problem of the exec-function ?
>
> >>> If you think about it, it should be obvious that you can't surround a
> >>> string to be compiled with any of the quotes that appear inside the
> >>> string to be compiled. That's about the only limitation I am aware of.
>
> >>> And, by the way, exec is a *statement*, not a function!
>
> >      exec ( Init_Code, PG.P_Globals )
>
> > I've really doubt that this is a statement,
> > unless I don't understand what a statement is.
>
> We'll have to conclude you don't, then, won't we ;-)
>

Two observations:

(1)

Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exec("print a", {'a': 42})
42
>>> exec "print a" in {'a': 42}
42

(2)

>From http://docs.python.org/3.0/whatsnew/3.0.html#removed-syntax
"""
Removed keyword: exec() is no longer a keyword; it remains as a
function. (Fortunately the function syntax was also accepted in 2.x.)
"""

There's still the triple-quotes-aren't-a-problem issue and the
perennial not-showing-code-and-error-output issue ... so by my
reckoning the score for this match is: Stef 1, RoW 2 :-)



More information about the Python-list mailing list