473,765 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(l ine)
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 1792
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(l ine)
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(l ine)
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
6279
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: LS - Al) - Receive the result in a string - Send an order (example: CD ..) - Receive the result in a string - Etc...
0
3033
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 I have used mixed case to help reading table names in my code. This is fine on windows but when I export the mySQL (using phpAdmin) and import it to Unix the tables being all lower case is a problem. So can I force the tables on the Windows...
3
2145
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++. It was ported from UNIX to run under Windows using .NET. If for no other reason than as an educational exercise, I have been wondering what it would take to rewrite the system under C#. The system currently has about a 100K “shared...
3
333
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++. It was ported from UNIX to run under Windows using .NET. If for no other reason than as an educational exercise, I have been wondering what it would take to rewrite the system under C#. The system currently has about a 100K “shared...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.