% sign in python?

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

    % sign in python?

    What does this operator do? Specifically in this context

    test.log( "[[Log level %d: %s]]" % ( level, msg ), description )

    (Tried googling and searching, but the "%" gets interpreted as an
    operation and distorts the search results)
  • Robert Bossy

    #2
    Re: % sign in python?

    korean_dave wrote:
    What does this operator do? Specifically in this context
    >
    test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
    >
    (Tried googling and searching, but the "%" gets interpreted as an
    operation and distorts the search results)
    >
    It's the string formatting operator:



    Btw, a good place to start searching would be:

    especially:


    Cheers
    RB

    Comment

    • Roy H. Han

      #3
      Re: % sign in python?

      The percent sign is a placeholder.

      For example, if
      level = 1
      msg = 'look'

      Then
      '[[Log level %d: %s]]' % ( level, msg )
      becomes
      '[[Log level 1: look]]'

      %d means insert an integer
      %s means insert a string

      You can also use dictionaries.
      d = {'string1': 'hey', 'string2': 'you'}
      Then
      '%(string1)s %(string2)s' % d
      becomes 'hey you'


      On Thu, Jul 17, 2008 at 10:33 AM, korean_dave <davidreynon@gm ail.comwrote:
      What does this operator do? Specifically in this context
      >
      test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
      >
      (Tried googling and searching, but the "%" gets interpreted as an
      operation and distorts the search results)
      --

      >

      Comment

      • Terry Reedy

        #4
        Re: % sign in python?



        korean_dave wrote:
        What does this operator do? Specifically in this context
        >
        test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
        >
        (Tried googling and searching, but the "%" gets interpreted as an
        operation and distorts the search results)
        Having seen a number of comments like this over the years (about the
        difficulty of searching for symbol meanings), I just started, last
        night, a symbol index listing nearly all Python syntax uses of
        non-alpha-or-digit ascii symbols. When I finish and upload it
        somewhere, I will post an announcement with the link.

        tjr

        Comment

        • Steven Howe

          #5
          Re: % sign in python?

          Terry Reedy wrote:
          >
          >
          korean_dave wrote:
          >What does this operator do? Specifically in this context
          >>
          >test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
          >>
          >(Tried googling and searching, but the "%" gets interpreted as an
          >operation and distorts the search results)
          >
          Having seen a number of comments like this over the years (about the
          difficulty of searching for symbol meanings), I just started, last
          night, a symbol index listing nearly all Python syntax uses of
          non-alpha-or-digit ascii symbols. When I finish and upload it
          somewhere, I will post an announcement with the link.
          >
          tjr
          >
          --

          >
          I thought, in this contexted, it was mapping operator.
          sph

          Comment

          • Jordan

            #6
            Re: % sign in python?

            On Jul 17, 3:42 pm, Terry Reedy <tjre...@udel.e duwrote:
            korean_dave wrote:
            What does this operator do? Specifically in this context
            >
            test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
            >
            (Tried googling and searching, but the "%" gets interpreted as an
            operation and distorts the search results)
            >
            Having seen a number of comments like this over the years (about the
            difficulty of searching for symbol meanings), I just started, last
            night, a symbol index listing nearly all Python syntax uses of
            non-alpha-or-digit ascii symbols.  When I finish and upload it
            somewhere, I will post an announcement with the link.
            >
            tjr
            That sounds great Terry! I look forward to seeing this.

            ~Jordan

            Comment

            • Tim Roberts

              #7
              Re: % sign in python?

              Steven Howe <howe.steven@gm ail.comwrote:
              >Terry Reedy wrote:
              >>
              >korean_dave wrote:
              >>What does this operator do? Specifically in this context
              >>>
              >>test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
              >
              >I thought, in this contexted, it was mapping operator.
              What??

              Python does not have a "mapping operator". It has a "map" function, but no
              equivalent operator.

              % is either the string formatting operator (when the left-hand operand is a
              string) or the modulo operator (when the left-hand operand is a number).
              --
              Tim Roberts, timr@probo.com
              Providenza & Boekelheide, Inc.

              Comment

              • Terry Reedy

                #8
                Re: % sign in python?



                Tim Roberts wrote:
                Steven Howe <howe.steven@gm ail.comwrote:
                >
                >Terry Reedy wrote:
                >>korean_dave wrote:
                >>>What does this operator do? Specifically in this context
                >>>>
                >>>test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
                >I thought, in this contexted, it was mapping operator.
                You miss clipped. I never wrote that. Please be careful, especially
                about attributing mis-information.
                What??
                >
                Python does not have a "mapping operator". It has a "map" function, but no
                equivalent operator.
                >
                % is either the string formatting operator (when the left-hand operand is a
                string) or the modulo operator (when the left-hand operand is a number).
                Which I learned 10 years ago. What I did write was a pre-announcement
                of a Python symbol glossary, which I just finished a first draft of.
                And now to bed ;-)

                Comment

                • Ken Starks

                  #9
                  Re: % sign in python?

                  Terry Reedy wrote:
                  >
                  >
                  korean_dave wrote:
                  >What does this operator do? Specifically in this context
                  >>
                  >test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
                  >>
                  >(Tried googling and searching, but the "%" gets interpreted as an
                  >operation and distorts the search results)
                  >
                  Having seen a number of comments like this over the years (about the
                  difficulty of searching for symbol meanings), I just started, last
                  night, a symbol index listing nearly all Python syntax uses of
                  non-alpha-or-digit ascii symbols. When I finish and upload it
                  somewhere, I will post an announcement with the link.
                  >
                  tjr
                  >
                  This will be excellent, Terry.

                  For the present case, perhaps we should also point out that in
                  python 3.0:

                  " Note

                  The formatting operations described here are obsolete and may go away in
                  future versions of Python. Use the new String Formatting in new code."

                  (Taken from the provisional documentation at:


                  )

                  Comment

                  • Tim Roberts

                    #10
                    Re: % sign in python?

                    Terry Reedy <tjreedy@udel.e duwrote:
                    >
                    >Tim Roberts wrote:
                    >Steven Howe <howe.steven@gm ail.comwrote:
                    >>
                    >>Terry Reedy wrote:
                    >>>korean_dav e wrote:
                    >>>>What does this operator do? Specifically in this context
                    >>>>>
                    >>>>test.log( "[[Log level %d: %s]]" % ( level, msg ), description )
                    >>>
                    >>I thought, in this contexted, it was mapping operator.
                    >
                    >You miss clipped. I never wrote that. Please be careful, especially
                    >about attributing mis-information.
                    If you count the signs, you'll see that I correctly attributed the
                    question to korean_dave, and the answer to Steve Howe. Steve's reply
                    contained your name, but there was no text from you in my post.
                    --
                    Tim Roberts, timr@probo.com
                    Providenza & Boekelheide, Inc.

                    Comment

                    Working...