473,406 Members | 2,894 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.

Carriage Return Problem with Python on Windows

The information posted at:

http://groups.google.com/groups?hl=e...net%26rnum%3D1

seemed to provide a solution to eliminating the line feed and causing
a carriage return for the text displayed in the IDLE window, (I want
to be able to overwrite displayed text - that is, eliminating the line
feed from occuring and causing a carriage return).

The comma at the end of the print command appeared to have eliminated
the line feed, (\n), but the carriage return, (\r) does not work. For
example, (logic borrowed from previously referenced thread):

for i in range(10) : print '\r' + `i`,

This produces a small square box before each number, (sorry - can't
duplicate the small square box here in this posting but if you were to
substitute X for box the output would look like this):

X1 X2 X3 X4 X5 X6 X7 X8 X9

as you can see the line feed has been eliminated but the carriage
return is not functioning as I would expect, (yes - its always about
me isn't it?).

I also tried a variation using sys.stdout.write and sys.stdout.flush
but the root cause is the issue with the carriage return.

Am I screwed or is there a way around this? I am running Windows XP
Home Edition using Python version 2.3.3 and IDLE version 1.0.2

Any help would be appreciated!

Thanks...
Jul 18 '05 #1
3 9237
On 2 Sep 2004 12:55:07 -0700, hi***@yahoo.com (Canes_Rock) declaimed the
following in comp.lang.python:

The comma at the end of the print command appeared to have eliminated
the line feed, (\n), but the carriage return, (\r) does not work. For
example, (logic borrowed from previously referenced thread):

for i in range(10) : print '\r' + `i`,

This produces a small square box before each number, (sorry - can't
duplicate the small square box here in this posting but if you were to
substitute X for box the output would look like this):

If you load a "unix" text file into Windows Notepad, you'll see
the same effect.

The Windows (MS-DOS) text rendering expects to see both <cr><lf>
to generate a newline; when it sees either character by itself, it tends
to throw up its hands and print the "unprintable control character" box.

At least, that's been my experience on W9x. (WordPad is a bit
more intelligent, and somehow determines the line-end convention of the
input file).
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 18 '05 #2
Canes_Rock wrote:
The information posted at:

http://groups.google.com/groups?hl=e...net%26rnum%3D1

seemed to provide a solution to eliminating the line feed and causing
a carriage return for the text displayed in the IDLE window, (I want
to be able to overwrite displayed text - that is, eliminating the line
feed from occuring and causing a carriage return).

The comma at the end of the print command appeared to have eliminated
the line feed, (\n), but the carriage return, (\r) does not work. For
example, (logic borrowed from previously referenced thread):

for i in range(10) : print '\r' + `i`,

This produces a small square box before each number, (sorry - can't
duplicate the small square box here in this posting but if you were to
substitute X for box the output would look like this):

X1 X2 X3 X4 X5 X6 X7 X8 X9

as you can see the line feed has been eliminated but the carriage
return is not functioning as I would expect, (yes - its always about
me isn't it?).


With IDLE, I just see 1 2 3 etc. all on one line, i.e. the same as you
do but without the boxes. PythonWin shows each number on its own line.
Python at the command prompt works correctly: only 9 is whown in the
end, since all the other numbers are overwritten. All that on Windows XP
Professional with Python 2.3.3.

It seems the behavior of '\r' is dependent on the terminal.

--
"Codito ergo sum"
Roel Schroeven
Jul 18 '05 #3
Here is a sample progress indicator class that should
(I think) answer your questions:

class progressbarClass:
def __init__(self, finalcount, progresschar=None):
import sys
self.finalcount=finalcount
self.blockcount=0
#
# See if caller passed me a character to use on the
# progress bar (like "*"). If not use the block
# character that makes it look like a real progress
# bar.
#
if not progresschar: self.block=chr(178)
else: self.block=progresschar
#
# Get pointer to sys.stdout so I can use the write/flush
# methods to display the progress bar.
#
self.f=sys.stdout
#
# If the final count is zero, don't start the progress gauge
#
if not self.finalcount : return
self.f.write('\n------------------ %
Progress -------------------1\n')
self.f.write(' 1 2 3 4 5 6 7 8 9 0\n')
self.f.write('----0----0----0----0----0----0----0----0----0----0\n')
return

def progress(self, count):
#
# Make sure I don't try to go off the end (e.g. >100%)
#
count=min(count, self.finalcount)
#
# If finalcount is zero, I'm done
#
if self.finalcount:
percentcomplete=int(round(100*count/self.finalcount))
if percentcomplete < 1: percentcomplete=1
else:
percentcomplete=100

#print "percentcomplete=",percentcomplete
blockcount=int(percentcomplete/2)
#print "blockcount=",blockcount
if blockcount > self.blockcount:
for i in range(self.blockcount,blockcount):
self.f.write(self.block)
self.f.flush()

if percentcomplete == 100: self.f.write("\n")
self.blockcount=blockcount
return

if __name__ == "__main__":
from time import sleep
pb=progressbarClass(8,"*")
count=0
while count<9:
count+=1
pb.progress(count)
sleep(0.2)

pb=progressbarClass(100)
pb.progress(20)
sleep(0.2)
pb.progress(47)
sleep(0.2)
pb.progress(90)
sleep(0.2)
pb.progress(100)
print "testing 1:"
pb=progressbarClass(1)
pb.progress(1)
"Canes_Rock" <hi***@yahoo.com> wrote in message
news:48**************************@posting.google.c om...
The information posted at:

http://groups.google.com/groups?hl=e...net%26rnum%3D1
seemed to provide a solution to eliminating the line feed and causing
a carriage return for the text displayed in the IDLE window, (I want
to be able to overwrite displayed text - that is, eliminating the line
feed from occuring and causing a carriage return).

The comma at the end of the print command appeared to have eliminated
the line feed, (\n), but the carriage return, (\r) does not work. For
example, (logic borrowed from previously referenced thread):

for i in range(10) : print '\r' + `i`,

This produces a small square box before each number, (sorry - can't
duplicate the small square box here in this posting but if you were to
substitute X for box the output would look like this):

X1 X2 X3 X4 X5 X6 X7 X8 X9

as you can see the line feed has been eliminated but the carriage
return is not functioning as I would expect, (yes - its always about
me isn't it?).

I also tried a variation using sys.stdout.write and sys.stdout.flush
but the root cause is the issue with the carriage return.

Am I screwed or is there a way around this? I am running Windows XP
Home Edition using Python version 2.3.3 and IDLE version 1.0.2

Any help would be appreciated!

Thanks...

Jul 18 '05 #4

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

Similar topics

4
by: Les Juby | last post by:
Can someone please help with a suggestion as to how I can keep the formatting (carriage returns) that the user enters into a memo field and then display that later. I figured I might be able to...
4
by: Josh | last post by:
Hi, I'm using System.Data.DataSet.ReadXml to convert some xml from a webservice to a DataSet. The xml looks like: <?xml version="1.0"...
2
by: Paradigm | last post by:
I want to insert a carriage return into a text field. I am using insert into and \n for newline. The MYSQL database is accessed by a MS Access front end and the text field appears with a small...
2
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this...
12
by: Nimmy | last post by:
Hi, I have a data file and I want to remove Carriage returns. Any one has any C code/program which does this? I am working on Windows XP machine.....I don't have access to UNIX machine. But I...
6
by: Laura D | last post by:
How can I identify a carriage return in C++? \r, \f, \0, \n, \t does not work. I have also tried !isprint(ch), iscntrl(ch), isspace(ch), etc....with no luck! I even poked around in the MSDN and...
11
by: TheRain | last post by:
Hi, I am trying to append a carriage return to my string using the string builder class, but when I do this the string ends up containing "13". I tried this multiple ways like so ...
1
by: nur123 | last post by:
Thanks in advance who will look at it. I have been encountering an issue which I can’t find a way out of it. What my pgm does: It (java codes) reads oracle table data and creates flat text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.