473,414 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Retaining Unix EOL when reading/writing in windows

Hello All,

I'm relatively new to PYTHON, using PYTHON 2.4 on Windows XP. I'm having a
problem as below. I've asked some other people in my office who are more
experienced in PYTHON, but they can't help.

I have a number of files created in UNIX that have the UNIX end of line
(EOL) character.

I want to read these files in python, modify some lines, and then write them
to a new file. This appears to work fine, however I find that the output
files have Windows EOL characters. This is a pain, as I want to compare the
before and after files to see if my changes are correct.

I've simplified my code down to something that just reads a file and then
writes it to a different file. I'm currently doing this with a bit of code
that looks something like this:

filename = "test.lwc"
outfile = open("test_out.lwc", 'w' )
readfile = open(filename,'r').readlines()

for line in readfile:
outfile.write(line)
outfile.close()

Is there a way I can do this, but retain the UNIX EOL characters?

Cheers,
Nick

__________________________________________________ _______________
Are you using the latest version of MSN Messenger? Download MSN Messenger
7.5 today! http://messenger.msn.co.uk

Jan 18 '06 #1
1 1782
Nick Wain wrote:
I'm relatively new to PYTHON, using PYTHON 2.4 on Windows XP. I'm having a
problem as below. I've asked some other people in my office who are more
experienced in PYTHON, but they can't help.

I have a number of files created in UNIX that have the UNIX end of line
(EOL) character.

I want to read these files in python, modify some lines, and then write
them to a new file. This appears to work fine, however I find that the
output files have Windows EOL characters. This is a pain, as I want to
compare the before and after files to see if my changes are correct.

I've simplified my code down to something that just reads a file and then
writes it to a different file. I'm currently doing this with a bit of code
that looks something like this:

filename = "test.lwc"
outfile = open("test_out.lwc", 'w' )
readfile = open(filename,'r').readlines()

for line in readfile:
outfile.write(line)
outfile.close()

Is there a way I can do this, but retain the UNIX EOL characters?


Try using the 'b'-flag as filemode.

filename = "test.lwc"
outfile = open("test_out.lwc", 'wb' )
readfile = open(filename,'rb').readlines()

for line in readfile:
outfile.write(line)
outfile.close()

Not sure how well that plays with readline, as I have no Windows machine at
hand.

Diez
Jan 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert PADOVANO | last post by:
Hello, I wish to establish a connection in language PHP on a UNIX server by telnet. In fact, I would like : - Connect to server by sending IP adress, login, password - Send an order (example:...
0
by: Gabriel Harrison | last post by:
Hi, I know from the MySQL documentation that Windows in not case sensitive and Unix is but can I force Windows to honour upper and lower case in table names. When writing the mySQL on windows...
3
by: alanrn | last post by:
I would like to start a dialog on how to implement the equivalent functionality of UNIX shared memory in .NET. I work with a factory automation system. The bulk of the system is written in C/C++....
3
by: alanrn | last post by:
I would like to start a dialog on how to implement the equivalent functionality of UNIX shared memory in .NET. I work with a factory automation system. The bulk of the system is written in C/C++....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.