Printing dots in single-line

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    Printing dots in single-line

    Hey there,

    I want to print some dots in a single-line while my program loads or does
    something. I tried with he following but it didn't work :(.

    while 1:
    print '.',

    Prints line of dots separated by a whitespace (. . . . . . etc). Is there a
    way I can get it to display them without that white space (.......etc)?

    Thanks


  • Jay O'Connor

    #2
    Re: Printing dots in single-line

    On Thu, 13 Nov 2003 12:22:01 -0300, <trofer@nic.nac .wdyn.de> wrote:
    [color=blue]
    >Hey there,
    >
    >I want to print some dots in a single-line while my program loads or does
    >something. I tried with he following but it didn't work :(.
    >
    >while 1:
    > print '.',
    >
    >Prints line of dots separated by a whitespace (. . . . . . etc). Is there a
    >way I can get it to display them without that white space (.......etc)?[/color]

    import sys

    while 1:
    sys.stdout.writ e(".")

    Comment

    • Bob Gailer

      #3
      Re: Printing dots in single-line

      At 08:22 AM 11/13/2003, trofer@nic.nac. wdyn.de wrote:
      [color=blue]
      >Hey there,
      >
      >I want to print some dots in a single-line while my program loads or does
      >something. I tried with he following but it didn't work :(.
      >
      >while 1:
      > print '.',
      >
      >Prints line of dots separated by a whitespace (. . . . . . etc). Is there a
      >way I can get it to display them without that white space (.......etc)?[/color]

      Try (depending on the output device)
      while 1:
      print '.\b',

      Bob Gailer
      bgailer@alum.rp i.edu
      303 442 2625


      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003

      Comment

      • Erik Max Francis

        #4
        Re: Printing dots in single-line

        Bob Gailer wrote:
        [color=blue]
        > At 08:22 AM 11/13/2003, trofer@nic.nac. wdyn.de wrote:
        >[color=green]
        > > Prints line of dots separated by a whitespace (. . . . . . etc). Is
        > > there a
        > > way I can get it to display them without that white space
        > > (.......etc)?[/color]
        >
        > Try (depending on the output device)
        > while 1:
        > print '.\b',[/color]

        A _far_ superior solution would be to simply not print the trailing
        spaces in the first place:

        while True:
        sys.stdout.writ e('.')
        sys.stdout.flus h()

        --
        Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
        __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
        / \
        \__/ Love is like war: easy to begin but very hard to stop.
        -- H.L. Mencken

        Comment

        • Duncan Booth

          #5
          Re: Printing dots in single-line

          Bob Gailer <bgailer@alum.r pi.edu> wrote in
          news:mailman.77 9.1069023820.70 2.python-list@python.org :
          [color=blue][color=green]
          >>while 1:
          >> print '.',
          >>
          >>Prints line of dots separated by a whitespace (. . . . . . etc). Is
          >>there a way I can get it to display them without that white space
          >>(.......etc )?[/color]
          >
          > Try (depending on the output device)
          > while 1:
          > print '.\b',[/color]

          Yuck.

          Either suppress the whitespace:

          import sys
          for i in range(10):
          sys.stdout.soft space=False
          print '.',

          or, much simpler, just don't use print:

          for i in range(10):
          sys.stdout.writ e('.')

          The reason I say that 'write' is simpler is that the softspace attribute
          works in a slightly confusing manner. You have to set it false every time
          before you print something if you don't want Python putting a leading space
          before the string it outputs. It gets sets true after each item that is
          printed unless a newline has just been output.

          --
          Duncan Booth duncan@rcp.co.u k
          int month(char *p){return(1248 64/((p[0]+p[1]-p[2]&0x1f)+1)%12 )["\5\x8\3"
          "\6\7\xb\1\x9\x a\2\0\4"];} // Who said my code was obscure?

          Comment

          • Stephen Ferg

            #6
            Re: Printing dots in single-line

            This is the 4th gotch on my Python gotchas page:

            Comment

            • Alok Singhal

              #7
              Re: Printing dots in single-line

              On Thu, 13 Nov 2003 12:22:01 -0300, trofe wrote:
              [color=blue]
              > Hey there,
              >
              > I want to print some dots in a single-line while my program loads or
              > does something. I tried with he following but it didn't work :(.
              >
              > while 1:
              > print '.',
              >
              > Prints line of dots separated by a whitespace (. . . . . . etc). Is
              > there a way I can get it to display them without that white space
              > (.......etc)?[/color]

              print('.' * n)

              where n is the number of dots you want to print.

              Incidentally, I saw other responses, and most of them suggest
              sys.stdout.writ e(). Is there a reason that is preferable over the
              solution above?

              Alok

              Comment

              • Rainer Deyke

                #8
                Re: Printing dots in single-line

                Alok Singhal wrote:[color=blue]
                > Incidentally, I saw other responses, and most of them suggest
                > sys.stdout.writ e(). Is there a reason that is preferable over the
                > solution above?[/color]

                Yes: the print statement is an abomination. It is a special-case syntax for
                a task that requires no special syntax, and will hopefully be deprecated in
                the future, the sooner the better.

                It is also not as general as sys.stdout.writ e. It may be important that the
                dots are printed in separate statements. For example, the dots could be
                used as a progress indicator.


                --
                Rainer Deyke - rainerd@eldwood .com - http://eldwood.com


                Comment

                • Jay O'Connor

                  #9
                  Re: Printing dots in single-line

                  Alok Singhal wrote:
                  [color=blue]
                  >On Thu, 13 Nov 2003 12:22:01 -0300, trofe wrote:
                  >
                  >
                  >[color=green]
                  >>Hey there,
                  >>
                  >>I want to print some dots in a single-line while my program loads or
                  >>does something. I tried with he following but it didn't work :(.
                  >>
                  >>while 1:
                  >> print '.',
                  >>
                  >>Prints line of dots separated by a whitespace (. . . . . . etc). Is
                  >>there a way I can get it to display them without that white space
                  >>(.......etc )?
                  >>
                  >>[/color]
                  >
                  >print('.' * n)
                  >
                  >where n is the number of dots you want to print.
                  >
                  >Incidentally , I saw other responses, and most of them suggest
                  >sys.stdout.wri te(). Is there a reason that is preferable over the
                  >solution above?
                  >
                  >[/color]

                  The solution you give will not work when you want to do processing
                  between each dot.

                  Comment

                  • Paul Rubin

                    #10
                    Re: Printing dots in single-line

                    "Rainer Deyke" <rainerd@eldwoo d.com> writes:[color=blue]
                    > Yes: the print statement is an abomination. It is a special-case syntax for
                    > a task that requires no special syntax, and will hopefully be deprecated in
                    > the future, the sooner the better.[/color]

                    Are you kidding? The example I keep asking about is the addition
                    operator (+). Why does anyone need to say 2+2 when they can say
                    2-(-2)? The addition operator is a special case syntax for the
                    subtraction operator where none is needed. Should we deprecate it?
                    I'd rather say that a practical language needs to make concessions to
                    the way users actually think.

                    Comment

                    • Jay O'Connor

                      #11
                      Re: Printing dots in single-line

                      Paul Rubin wrote:
                      [color=blue]
                      >"Rainer Deyke" <rainerd@eldwoo d.com> writes:
                      >
                      >[color=green]
                      >>Yes: the print statement is an abomination. It is a special-case syntax for
                      >>a task that requires no special syntax, and will hopefully be deprecated in
                      >>the future, the sooner the better.
                      >>
                      >>[/color]
                      >
                      >Are you kidding? The example I keep asking about is the addition
                      >operator (+). Why does anyone need to say 2+2 when they can say
                      >2-(-2)? The addition operator is a special case syntax for the
                      >subtraction operator where none is needed. Should we deprecate it?
                      >I'd rather say that a practical language needs to make concessions to
                      >the way users actually think.
                      >
                      >[/color]


                      Well, okay then :) Personally, print bothers me because there is no
                      receiver. As an OO developer, I'm used to thinking usually iin terms of
                      "object.met hod" and the fact that print is just sorta this standalone
                      thing out there with no receiver doesn't match the way I think.
                      However, it's not really a function either as it doesn't use function
                      syntax. It's just sorta there. It really doesn't fit in with any of the
                      basic idioms I use when thinking about developing software

                      Comment

                      • Michael Hudson

                        #12
                        Re: Printing dots in single-line

                        "Rainer Deyke" <rainerd@eldwoo d.com> writes:
                        [color=blue]
                        > Alok Singhal wrote:[color=green]
                        > > Incidentally, I saw other responses, and most of them suggest
                        > > sys.stdout.writ e(). Is there a reason that is preferable over the
                        > > solution above?[/color]
                        >
                        > Yes: the print statement is an abomination.[/color]

                        Says you.

                        I mean, just take a look at Joe Strout's brilliant little "python
                        for beginners" page. Replace all print-statements with
                        sys.stdout.writ e( string.join(map (str, args)) + "\n") and you
                        surely won't get any new beginners. And That Would Be A Very Bad
                        Thing.
                        -- Fredrik Lundh, 27 Aug 1996

                        Cheers,
                        mwh

                        --
                        : Giant screaming pieces of excrement, they are.
                        I have a feeling that some of the people in here have a
                        MUCH more exciting time relieving themselves than I do.
                        -- Mike Sphar & Dave Brown, asr

                        Comment

                        Working...