Strange Python problem on Linux.

Thomas A. Bryan tbryan at python.net
Tue Feb 29 22:20:41 EST 2000


Paul Jackson wrote:

> Along the lines of the previous suggestion that the "#! ..." line
> might have odd chars, in addition to trying 'cat -v', also try:
> 
>     head -1 mdef.py > silly.py
>     echo 'print "What's wrong?"' >> silly.py
>     chmod u+x silly.py
>     ./silly.py

Yep.  I tried them both for thoroughness.  There was a ^M (hex(13))
at the end of the #! line.  Linux was picking it up as part of the 
command to run.  I would have expected it to show up as extra whitespace 
or control characters when I traced the program, but it didn't.  I 
should have thought of cat -v (or Emacs hexl-mode) much earlier.

$ strace -o out.trace mdef.py
strace: exec: No such file or directory
$ cat out.trace 
execve("./mdef.py", ["mdef.py"], [/* 28 vars */]) = 0

One reason I never looked for the ^M was that I use Xemacs at work.
It shows the ^M.  Emacs seems to do the translation on the fly for 
me, so I didn't realize that the file had MS-corrupted line endings.

> That or just edit 'mdef.py', deleting the first line and rekeying
> it from scratch, if you are more interested in cures than in
> a diagnosis.

No.  I hate it when I fix something but don't know what was 
originally wrong.  If I know a problem's symptoms, cause, and 
solution, then I'll be more effective the next time I encounter it.

> =======================================================================
> I won't rest till it's the best ...        Software Production Engineer

afraid-of-professionals-who-rhyme-<wink>-ly yours

---Tom



More information about the Python-list mailing list