Shebang line problems and python

Blaine brlafreniere at gmail.com
Thu Sep 17 07:46:27 CEST 2009


On Sep 16, 10:46 pm, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:
> On Wed, 16 Sep 2009 21:35:21 -0700, Blaine wrote:
> > blaine at attila ~/tmp $ cat ./shebang-test
> > #!/usr/bin/python
> > import sys
> > sys.stdout.write("Hello, world.\n")
> > blaine at attila ~/tmp $ ./shebang-test
> > ./shebang-test: line 2: import: command not found ./shebang-test: line
> > 3: syntax error near unexpected token `"Hello, world.\n"'
> > ./shebang-test: line 3: `sys.stdout.write("Hello, world.\n")'
>
> I've seen something similar to this, which was caused by invisible ctrl-Z
> characters somehow getting into my text file. If you view a hexdump of
> the file, are there any unexpected characters in the file, particularly
> before or between the # ! characters?

I'm not sure if there is a Ctrl+Z in here... but, here's the output:
blaine at attila ~/tmp $ hexdump shebang-test
0000000 2123 752f 7273 622f 6e69 702f 7479 6f68
0000010 0a6e 6d69 6f70 7472 7320 7379 730a 7379
0000020 732e 6474 756f 2e74 7277 7469 2865 4822
0000030 6c65 6f6c 202c 6f77 6c72 2e64 6e5c 2922
0000040 000a
0000041


> If not, what happens if you run the file directly with Python?
>
> python shebang-test

blaine at attila ~/tmp $ python shebang-test
Hello, world.




More information about the Python-list mailing list