print there!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Godwin Burby

    #1

    print there!

    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.c sv',
    for i,row in enumerate(reade r):
    # inserts or updates the database
    print i,
    This displays on the screen as :
    c:\godwin\bl.cs v 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?

  • Fredrik Lundh

    #2
    Re: print there!

    Godwin Burby wrote:
    [color=blue]
    > print 'c:\godwin\bl.c sv',
    > for i,row in enumerate(reade r):
    > # inserts or updates the database
    > print i,
    > This displays on the screen as :
    > c:\godwin\bl.cs v 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?[/color]

    carriage return is your friend:

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

    </F>



    Comment

    • Godwin Burby

      #3
      Re: print there!

      i think u've misunderstood my question. Your solution will print on a
      new line as below:
      c:\godwin\bl.cs v 1
      c:\godwin\bl.cs v 2
      c:\godwin\bl.cs v 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.cs v
      ^
      If i were to do it in the c language i would use the conio.h and gotxy
      function with printf.
      printf("c:\\god win\\bl.csv");
      for(i=0;i<rows; i++)
      {
      gotoxy(10,20);
      printf("%d",row s+1);
      }
      Sorry for bothering u again!

      Comment

      • Godwin Burby

        #4
        Re: print there!

        thanks :) It works beautifully.

        Comment

        • Steven D'Aprano

          #5
          Re: print there!

          On Tue, 20 Sep 2005 14:06:23 +0200, Fredrik Lundh wrote:
          [color=blue]
          > Godwin Burby wrote:
          >[color=green]
          >> print 'c:\godwin\bl.c sv',
          >> for i,row in enumerate(reade r):
          >> # inserts or updates the database
          >> print i,
          >> This displays on the screen as :
          >> c:\godwin\bl.cs v 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?[/color]
          >
          > carriage return is your friend:
          >
          > filename = 'c:\\godwin\\bl .csv',
          > for i,row in enumerate(reade r):
          > # inserts or updates the database
          > print "\r" + filename, i,
          > print[/color]

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


          --
          Steven.


          Comment

          • Fredrik Lundh

            #6
            Re: print there!

            Godwin Burby wrote:
            [color=blue]
            > i think u've misunderstood my question. Your solution will print on a
            > new line as below:
            > c:\godwin\bl.cs v 1
            > c:\godwin\bl.cs v 2
            > c:\godwin\bl.cs v 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:[/color]

            I think u've misunderstood the answer.

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

            </F>



            Comment

            • davbrow@gmail.com

              #7
              Re: print there!

              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

              Comment

              • Godwin Burby

                #8
                Re: print there!

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

                Comment

                Working...