First program

Chris Rebert clp2 at rebertia.com
Sat Jun 12 05:17:44 EDT 2010


On Sat, Jun 12, 2010 at 2:03 AM, Phil H <skilphil at gmail.co.za> wrote:
> Hi,
> Trying my hand with Python but have had a small hiccup.
> Reading  'A byte of Python' and created helloworld.py as directed.
>
> #!/usr/bin/python
> # filename : helloworld.py
> print 'Hello World'
>
> At the terminal prompt cd to the file location and run from the prompt.
>
> phil at grumpy:~/projects/python$ python helloworld.py
> Hello World
>
> All fine.
>
> Then I tried the following as described in the tutorial and get the
> following error
>
> phil at grumpy:~/projects/python$ chmod a+x helloworld.py
> phil at grumpy:~/projects/python$ ./helloworld.py
> bash: ./helloworld.py: /usr/bin/python^M: bad interpreter: No such file
> or directory
>
> The permissions are: rwxr-xr-x.
>
> Any help appreciated

Seems your file is using Windows line endings (CR+LF) rather than Unix
line endings (just LF), which is messing up the processing of the
shebang line.
Run your file thru `dos2unix`
(http://gd.tuwien.ac.at/linuxcommand.org/man_pages/dos2unix1.html ).
Further info: http://en.wikipedia.org/wiki/Newline

Also, a more generic shebang line is usually recommended:
#!/usr/bin/env python

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list