Interpreter problem
Ivan Van Laningham
ivanlan at pauahtun.org
Fri Apr 8 13:40:15 EDT 2005
Hi All--
Steve Holden wrote:
>
> > It's odd that deleting the line and reentering it on the Linux box did
> > not correct the problem. Perhaps vim recognized the format as having
> > cr-lf and inserted it even though I was editing on Linux.
> >
> > Anyhow, it would have been a long time before I got this one. Thanks.
> >
> A pleasure - just passing on payback for the huge amounts of help I've
> had here myself. See also my post in reply to rbt's latest for remarks
> on other possible fixes using vim.
>
Vim is pretty smart. If you edit something in DOS mode, it'll preserve
it. If you edit it in UNIX mode, it'll preserve that too. Thus, if you
copy a dos file to a unix and edit with vim on both systems, it'll stay
dos unless you change it; this is a Good Thing(tm). You run into
problems with mixed line endings, or when it makes a difference to the
program/OS (the shebang trick).
In vim, if you run
:se fileformat?
it'll tell you exactly what file format you're using. The choices are
(surprise) unix and dos.
To change the file format of a file explicitly, simply issue the command
:set fileformat=dos
or
:set fileformat=unix
When you write the file, it'll be saved exactly the way you specify.
Note that you get the ^M at the ends of lines when a file you've been
editing in one mode shifts to another and you have to reload the file.
Reading [open(foofile,"rb")] & re-writing [open(foofile,"wb")] a file
will do this if you are not excruciatingly careful.
If you don't have dos2unix on your win system, but do have cat, you can
use cat -d.
#!/bin/sh
cat -d $1 > snot
mv snot $1
(Prone to error, of course.)
<insert-std-disclaimers-about-vim-vs-classic-vi-behaviours-here>-ly
y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
More information about the Python-list
mailing list