By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

print there!

P: n/a
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?

Sep 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Godwin Burby wrote:
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>

Sep 20 '05 #2

P: n/a
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!

Sep 21 '05 #3

P: n/a
thanks :) It works beautifully.

Sep 21 '05 #4

P: n/a
On Tue, 20 Sep 2005 14:06:23 +0200, Fredrik Lundh wrote:
Godwin Burby wrote:
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


That may not be enough. You may need to flush the print buffer using
sys.stout.flush().
--
Steven.
Sep 21 '05 #5

P: n/a
Godwin Burby wrote:
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>

Sep 21 '05 #6

P: n/a
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

Sep 21 '05 #7

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

Sep 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.