print there!

G

Godwin Burby

Dear Pythoneer,
I am writing a python script which inserts or updates a database
from a csv file. i've done the functionality. But i would to like to
show the user the current row being inserted or updated in the screen.
This can be done as follows:
print 'c:\godwin\bl.csv',
for i,row in enumerate(reader):
# inserts or updates the database
print i,
This displays on the screen as :
c:\godwin\bl.csv 1 2 3 4 5 6 7 8
^
But i want it to show the above numbers on the same spot denoted by the
carat character. Can it be done with print statement or any other trick?
 
F

Fredrik Lundh

Godwin said:
print 'c:\godwin\bl.csv',
for i,row in enumerate(reader):
# inserts or updates the database
print i,
This displays on the screen as :
c:\godwin\bl.csv 1 2 3 4 5 6 7 8
^
But i want it to show the above numbers on the same spot denoted by the
carat character. Can it be done with print statement or any other trick?

carriage return is your friend:

filename = 'c:\\godwin\\bl.csv',
for i,row in enumerate(reader):
# inserts or updates the database
print "\r" + filename, i,
print

</F>
 
S

Steven D'Aprano

carriage return is your friend:

filename = 'c:\\godwin\\bl.csv',
for i,row in enumerate(reader):
# inserts or updates the database
print "\r" + filename, i,
print

That may not be enough. You may need to flush the print buffer using
sys.stout.flush().
 
G

Godwin Burby

i think u've misunderstood my question. Your solution will print on a
new line as below:
c:\godwin\bl.csv 1
c:\godwin\bl.csv 2
c:\godwin\bl.csv 3
But i want this number to diplay their value increase on the same line
on the same sport itself without printing the filename multiple times
on multiple lines:
c:\godwin\bl.csv
^
If i were to do it in the c language i would use the conio.h and gotxy
function with printf.
printf("c:\\godwin\\bl.csv");
for(i=0;i<rows;i++)
{
gotoxy(10,20);
printf("%d",rows+1);
}
Sorry for bothering u again!
 
F

Fredrik Lundh

Godwin said:
i think u've misunderstood my question. Your solution will print on a
new line as below:
c:\godwin\bl.csv 1
c:\godwin\bl.csv 2
c:\godwin\bl.csv 3
But i want this number to diplay their value increase on the same line
on the same sport itself without printing the filename multiple times
on multiple lines:

I think u've misunderstood the answer.

filename = 'c:\\godwin\\bl.csv'
for i,row in enumerate(reader):
# inserts or updates the database
print "\r" + filename, i, # <-- notice the trailing comma
print

</F>
 
D

davbrow

It's possible you will need to run python -u for this to behave as
expected. Otherwise python may buffer the output until it sees a
newline so you only see the last result.

-- David
 
G

Godwin Burby

i didn't notice it and i'm really sorry. it works beautifully! thanks
once again :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,005
Latest member
ChasityFan

Latest Threads

Top