473,406 Members | 2,707 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,406 software developers and data experts.

bug? file.write('\n') produces a carriage return and a line feed

jcb
The following code in Python 2.3
f = file('t.txt', 'wt')
f.write('\n')
f.close()

writes
0D0A to the file.

Is this a bug or expected behavior?
It sure took me by surprise.

If it is not a bug, is this behavior documented?

Dec 15 '05 #1
2 5576
jc*@iteris.com wrote:
...
0D0A to the file.

Is this a bug or expected behavior?
It sure took me by surprise.


You're running Windows, right? Then, this is expected behaviour, as Windows
treats text and binary files different, extending \n to \r\n (as that is
the Windows end of line marker).

If you want to only write \n to the file, use:

f = file("t.txt","wb")

....

windows-line-feeds-are-from-hell'ly yours,
--- Heiko.
Dec 15 '05 #2
jcb
Thanks much.

Yes, I am using Windows.

Dec 15 '05 #3

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

Similar topics

3
by: Romain | last post by:
Hello, I am writing out a binary file. I figured that the number "10" is automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are line feed and carriage return. I know it does...
2
by: Larry Rekow | last post by:
A friend's unix application produces various reports daily as flat text files. I link these files as tables in an Access (2000) database. After linking, all of these reports begin with a...
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
5
by: james | last post by:
I'm using "FILE" function to write an array in a file and in this way I see that when is present a line feed (10) the function automatically insert a carriage return(13). This cause an error when i...
5
by: Neil Robbins | last post by:
I have a text file that stores a number of records that I need to access in a vb.net application. Each of the fields that make up a record are of a fixed number of bytes. So for instance there is...
5
by: Lyle | last post by:
How do get a line control on the end of a line using the streamwriter.writeline (not carriage line control)? How do you get the following command to print a quote in the file? I have tried using...
3
by: Gillian Steele | last post by:
I'm trying to import data into a memo field by running an append query. The data is to be imported as if it was entered with separate lines in the memo field. I have tried inserting chr(13)s...
7
by: Michael Castleton | last post by:
When I open a csv or txt file with: infile = open(sys.argv,'rb').readlines() or infile = open(sys.argv,'rb').read() and then look at the first few lines of the file there is a carriage return...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
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: 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
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
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...
0
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,...
0
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...

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.