question on the compile built in function. Filename ignored?

Jp Calderone exarkun at intarweb.us
Wed Apr 30 12:25:28 EDT 2003


On Wed, Apr 30, 2003 at 04:01:07PM +0000, Alex wrote:
> I am fairly to new to Python, so please bear with me.
> 
> I am trying to use the built in function compile.  The filename argument
> seems to be ignored no matter what I try.  According to the docs, it should
> be used in the output error message.  Here is a simple example:
> 
> Python 2.2.2 (#1, Apr 16 2003, 22:00:16)
> [GCC 3.2.1 20021207 (Gentoo Linux 3.2.1-20021207)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> compile(':\n', 'abc', 'exec')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "<string>", line 1
>     :
>     ^
> SyntaxError: invalid syntax
> 
> 
> From the docs I would expect the line 
> 
>   File "<string>", line 1
> 
> to read
> 
>   File "abc", line 1
> 
> 
> What am I missing?

  SyntaxErrors are caught earlier than most other errors.  If you compile
something that is syntactically correct but raises some other exception,
you'll see the filename you specified in the traceback you get when you exec
the result of the compile() call.

  Jp

-- 
Where a calculator on the ENIAC is equipped with 18,000 vacuum tubes and
weighs 30 tons, computers in the future may have only 1,000 vacuum tubes and
weigh only 1.5 tons.    -- Popular Mechanics, March 1949
-- 
 up 41 days, 13:04, 5 users, load average: 0.13, 0.16, 0.09





More information about the Python-list mailing list