python 2.0 won't run scripts with \r\n line termination on RH7?

D-Man dsh8290 at rit.edu
Tue Feb 13 10:35:56 EST 2001


On Tue, Feb 13, 2001 at 03:59:47PM +0100, Steve Purcell wrote:
| Cesar Rabak wrote:
| > 
| > So elaborating, on your reasoning, Steve, I think the 'sollution' would
| > be the OP to have a kind of "header" or macro in his favorite editor
| > which inserts the correct line in whatever OS be the script being
| > written.
| 
| Perhaps, although what's the simplest thing? Save the file in UNIX text
| format (there must be Windows editors that support this).

There are -- I use gvim :-).

:set fileformat=unix


| 
| As Toby Dickenson suggests, you can use a technique like CVS' filters to
| transparently correct line endings according to the system on which files are
| checked out from source code control. In this case, files are usually saved
| in UNIX format in the source repository, and Windowsified as necessary on
| checkout.
| 
| I think there's a utility that ships with Python for changing the #! line of
| a number of scripts -- perhaps that would help. Anybody remember the name?
| 

I don't know if one came with it, but it shouldn't be hard to make
such a thing.  (Just be sure to open the file in _binary_ not text
mode) It would be simplest to use a RandomAccessFile type of interface
(there is a Java class by that name) and simply change the first \r\n
to \n\n.

In (g)vim you could type the following commands :

:1 
:set binary
:s/^V^M//


where ^V means Ctrl-V and ^M means Ctrl-M (or enter, in this case)

-D





More information about the Python-list mailing list