473,700 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.writ e and sys.stdout.flus h
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 9308
On 2 Sep 2004 12:55:07 -0700, hi***@yahoo.com (Canes_Rock) declaimed the
following in comp.lang.pytho n:

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 "unprintabl e 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.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.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 progressbarClas s:
def __init__(self, finalcount, progresschar=No ne):
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=prog resschar
#
# Get pointer to sys.stdout so I can use the write/flush
# methods to display the progress bar.
#
self.f=sys.stdo ut
#
# 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 "percentcomplet e=",percentcomp lete
blockcount=int( percentcomplete/2)
#print "blockcount=",b lockcount
if blockcount > self.blockcount :
for i in range(self.bloc kcount,blockcou nt):
self.f.write(se lf.block)
self.f.flush()

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

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

pb=progressbarC lass(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=progressbarC lass(1)
pb.progress(1)
"Canes_Rock " <hi***@yahoo.co m> wrote in message
news:48******** *************** ***@posting.goo gle.com...
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.writ e and sys.stdout.flus h
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
7315
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 use: 'replace carriage returns with BRs comment=Replace(comment, chr(13), "<br>") but obviously net.! The <pre> tag doesn't sem to help either as the embedded return is
4
18692
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" encoding="UTF-8"?><root><prioritiesTable><description>blah blah blah blah</description></prioritiesTable></root> The important thing here is the which I beleive should be a single
2
7561
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 square where the new line should be. It appears that the \n is interpreted in Access differently. Is there a way of putting a carriage return into the field so that it is seen as such by Accesss? Alex
2
2946
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 note field contains carriage returns. When I import a note field that has carriage returns, what shows up in the Access field are vertical black lines where the carriage return should be.
12
5610
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 need to send this data file to the Unix machine once I remove the carriage retunrns from my XP machine. Thanks
6
17591
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 found some code that MS claims will save a file in unix format and I cut and pasted into my program(and made changes to suit): ..... char ch; char temp="\0"; //Open the file for reading in binarymode. ifstream fp_read(filename.c_str(),...
11
8458
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 sb->Append('\r'); and also
1
4177
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 data files. Another part of the program distributes the extracted text files to unix systems. Problem first occurred: Opening those files in Unix box shows carriage return in the middle of the record as well as at the end of the record.
0
9217
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9078
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
8928
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
7815
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
6563
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
5903
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
4407
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
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3094
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.