[Tutor] Printing Problem python 3

Vern Ceder vceder at canterburyschool.org
Thu Apr 30 04:34:21 CEST 2009


Dave Crouse wrote:
> I got the same thing with idle, but when running as a script, it's not
> the same, it errors. I tried it on Windows and Linux.
> 
> -------------------------------------------
> 
> [davec at Arch64 Python]$ less test.py
> #/usr/bin/python3
> print ('The \"This is a test \" {')
> 
> [davec at Arch64 Python]$ sh test.py
> test.py: line 3: syntax error near unexpected token `'The \"This is a
> test \" {''
> test.py: line 3: `print ('The \"This is a test \" {')'

Maybe I'm missing something, but this error is because you're running a 
Python script using the Linux shell, probably bash as the interpreter 
instead of Python. Also, if you're running it on its own as a script, 
you'd want to add a '!' after the '#' - otherwise it's just a comment, 
not setting the interpreter.

To run a Python file as a script, you'd need to do:

[davec at Arch64 Python]$ python3 test.py
(or just ./test.py if it's executable and the interpreter is set using 
'#!/usr/bin/python3')

When I do that, it works for me just fine without doubling the '{'

Cheers,
Vern
-- 
This time for sure!
    -Bullwinkle J. Moose
-----------------------------
Vern Ceder, Director of Technology
Canterbury School, 3210 Smith Road, Ft Wayne, IN 46804
vceder at canterburyschool.org; 260-436-0746; FAX: 260-436-5137


More information about the Tutor mailing list