Tuesday 5 December 2017

I get syntax error when I execute this python scripts but not when I invoke the interpreter

in a file called test.py I have the following
code


#!/usr/bin/python3
with
open('test.txt','w') as File:

print(1,file=File)

When I
do


$ python3
test.py

It runs fine. But when I
do


$ chmod +x test.py
$
./test.py

I get a
SyntaxError:


 File "./test.py", line
4
print(1,file=File)
^
SyntaxError: invalid
syntax

Any one has any idea why?
Thank you


I'm running Python 3.3.1 in Ubuntu
13.04

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...