Newb question: underscore

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

    Newb question: underscore

    What is this doing?

    print >fd, _(__doc__)


    I'm guessing line-splitting __doc__ into a list, but what's that
    leading underscore do?

    Thanks!
  • Ben Finney

    #2
    Re: Newb question: underscore

    Skye <spoier@gmail.c omwrites:
    What is this doing?
    >
    print >fd, _(__doc__)
    Without any context, it's impossible to know.
    I'm guessing line-splitting __doc__ into a list, but what's that
    leading underscore do?
    Look at the rest of the module to see where that name comes from;
    perhaps an assignment, or an 'import foo as _'.

    My guess would be someone has used the common convention of naming the
    "get the corresponding localised version of this string from the
    application's gettext database" function as '_' for convenience.

    That's only a guess though; you should believe the code you have in
    front of you, not my guesses.

    --
    \ "Pinky, are you pondering what I'm pondering?" "Well, I think |
    `\ so, Brain, but 'apply North Pole' to what?" -- _Pinky and The |
    _o__) Brain_ |
    Ben Finney

    Comment

    • Gary Herron

      #3
      Re: Newb question: underscore

      Skye wrote:
      What is this doing?
      >
      print >fd, _(__doc__)
      >
      >
      I'm guessing line-splitting __doc__ into a list, but what's that
      leading underscore do?
      >
      It's calling a function with a single argument, like sqrt(x), except the
      function is named _ and the argument is named __doc__. The underscores
      have no special significance here, but they do make the code hard to read.

      The first part of the statement directs the print to send the output to
      a file, named fd, which was presumably opened earlier ... but I don't
      think that was part of your question.

      Gary Herron

      Comment

      • Skye

        #4
        Re: Newb question: underscore

        Ohh, it's a function _() call. Now it makes sense.

        Of course Python would be consistent... I was expecting trickery!

        It's actually from the Mailman source, def _(s) is a string function
        for i18n

        Thanks,
        Skye

        Comment

        • bvdp

          #5
          Re: Newb question: underscore

          My guess would be someone has used the common convention of naming the
          "get the corresponding localised version of this string from the
          application's gettext database" function as '_' for convenience.
          >
          Funny that this comes up.

          I just noticed this in some code I was looking at the other day. A
          number of statements in the form:

          print _(something)

          My question is: Why would anyone decide to obfuscate something as easy
          to read as Python??? At first I thought that they were making a function
          out of print (which makes some sense), but I don't think that is the
          case. I tried (not very hard) to trace back the code to figure out where
          _() is being assigned, but gave up. Oh, this is in the gdesklets package
          if anyone is interested.


          **** Listen to my CD at http://www.mellowood.ca/music/cedars ****
          Bob van der Poel ** Wynndel, British Columbia, CANADA **
          EMAIL: bob@mellowood.c a
          WWW: http://www.mellowood.ca

          Comment

          • John Fabiani

            #6
            Re: Newb question: underscore

            Skye wrote:
            What is this doing?
            >
            print >fd, _(__doc__)
            >
            >
            I'm guessing line-splitting __doc__ into a list, but what's that
            leading underscore do?
            >
            Thanks!
            I think it is standard practice to use the underscore for unicode converts.

            Comment

            • Ben Finney

              #7
              Re: Newb question: underscore

              bvdp <bob@mellowood. cawrites:
              My question is: Why would anyone decide to obfuscate something as easy
              to read as Python???
              They didn't decide to obfuscate; they decided to follow a
              strongly-expected convention for the name of that function by existing
              users of the 'gettext' functionality, in contexts that predate the
              appearance of that functionality in Python.

              --
              \ Hercules Grytpype-Thynne: "Well, Neddie, I'm going to be |
              `\ frank." Ned Seagoon: "Right, I'll be Tom." Count Moriarty: |
              _o__) "I'll be Gladys." *slap* -- The Goon Show, _World War I_ |
              Ben Finney

              Comment

              • cokofreedom@gmail.com

                #8
                Re: Newb question: underscore

                My question is: Why would anyone decide to obfuscate something as easy
                to read as Python???
                >
                They didn't decide to obfuscate; they decided to follow a
                strongly-expected convention for the name of that function by existing
                users of the 'gettext' functionality, in contexts that predate the
                appearance of that functionality in Python.
                >
                Well _ can also mean the previous output statement that wasn't null,
                so it has OTHER uses...

                Comment

                • Bruno Desthuilliers

                  #9
                  Re: Newb question: underscore

                  cokofreedom@gma il.com a écrit :
                  >>My question is: Why would anyone decide to obfuscate something as easy
                  >>to read as Python???
                  >They didn't decide to obfuscate; they decided to follow a
                  >strongly-expected convention for the name of that function by existing
                  >users of the 'gettext' functionality, in contexts that predate the
                  >appearance of that functionality in Python.
                  >>
                  >
                  Well _ can also mean the previous output statement that wasn't null,
                  In the shell only IIRC.

                  Comment

                  • Bruno Desthuilliers

                    #10
                    Re: Newb question: underscore

                    John Fabiani a écrit :
                    Skye wrote:
                    >
                    >What is this doing?
                    >>
                    > print >fd, _(__doc__)
                    >>
                    >>
                    >I'm guessing line-splitting __doc__ into a list, but what's that
                    >leading underscore do?
                    >>
                    >Thanks!
                    I think it is standard practice to use the underscore for unicode converts.
                    Actually, it's for i18n, not for encoding.

                    Comment

                    Working...