From: Danny Y. <dy...@hk...> - 2002-07-09 17:48:15
|
On Tue, 9 Jul 2002, Frank Cohen wrote: > Tripple quoted strings evaluate to a single quote mark that is then > taken literally as a quote. So if you try: > > print '''hi''' > > the interprepeter parses that to mean > > print 'hi' > > This works in both interactive and batch mode. > > The lexical error you see is when you are in the interpreter and type > in '''. The interpreter thinks you have just asked it to evaluate > > ' > > which is indeed an error. But triple quoted strings are supposed to allow us to type across multiple lines. In CPython, we can create a string that spans multiple lines by just typing it out between triple quotes: ### Python 2.1.1 (#1, Sep 14 2001, 17:14:00) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-85)] on linux2 Type "copyright", "credits" or "license" for more information. >>> '''hello ... world''' 'hello\nworld' ### Jython's interactive lexer needs to wait until it sees the next triple quote before trying to evaluate the whole thing, since the string can span several lines. I tried using a continuation character to get around this, but with the same problems in interactive mode: ### [dyoo@tesuque dyoo]$ jython Jython 2.1 on java1.4.0 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> 'hello\ Traceback (innermost last): (no code object) at line 0 File "<console>", line 2 SyntaxError: Lexical error at line 2, column 0. Encountered: <EOF> after : "" ### That is, continuation lines don't continue. The interactive interpreter doesn't give me the opportunity to continue typing out the next line, and I think this is specifically an interactive issue. Hope this helps! |