[Tutor] Permissions Problem with Python [magic lines need to
be the very first line of a file]
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Mon Sep 15 17:52:57 EDT 2003
On Mon, 15 Sep 2003, Jorge Godoy wrote:
> Peter Brown <peterabrown at froggy.com.au> writes:
>
> > I type /usr/TP/foo.py at the bash prompt, this is the fully qualified
> > path - then it says no such file or directory.
>
> The first thing to try is to change
>
> #!/usr/bin/env python
>
> for
>
> #!/usr/bin/python
Hello!
Also, make sure that the magic line really is the very first line in the
file. If there's a newline that precedes the magic line, then that will
interfere with the magic-line system that Unix uses. For example, let's
say we have two programs 'hello.py' and 'hello2.py':
###
bash-2.05a$ ls -l hello.py hello2.py
-rwxr-xr-x 1 dyoo staff 38 Sep 15 14:49 hello.py
-rwxr-xr-x 1 dyoo staff 39 Sep 15 14:49 hello2.py
bash-2.05a$
bash-2.05a$ cat hello.py
#!/usr/bin/python
print "hello world"
bash-2.05a$ ./hello.py
hello world
bash-2.05a$ cat hello2.py
#!/usr/bin/python
print "hello world"
bash-2.05a$ ./hello2.py
./hello2.py: print: command not found
###
Both programs are executable --- but notice that in the second example,
the extra newline causes the system not to find the magic line where it
expects to see it! So it responds with 'command not found'. I don't know
if this is the issue you're running into, but I might as well throw
something out and see if it sticks... *grin*
If you have the time, try this to help us debug things:
###
print repr(open('/usr/TP/foo.py', 'rb').read(160))
###
If you show the result to us, we should be able to see about two lines
worth of bytes. I just want to make sure we're not chasing some silly
newline/carriage-return problem... *grin*
Talk to you later!
More information about the Tutor
mailing list