'Hidden Features of Python'

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

    'Hidden Features of Python'

    Having read through the link below I finally managed to grasp some
    concepts that I only read about in the docs but never got to really
    understand. Maybe it will be helpful for people like myself who are
    not yet fully comfortable with some of Python's `hidden' features.

    What are the lesser-known but useful features of the Python programming language? Try to limit answers to Python core. One feature per answer. Give an example and short description of the feature,...

  • Joe Strout

    #2
    Re: 'Hidden Features of Python'

    On Oct 17, 2008, at 10:00 AM, coldpizza wrote:
    Thanks, there are a lot of useful nuggets there. However, can anybody
    explain the "Main messages" one? It doesn't include any explanatory
    text at all, just a code snippet:

    import this
    # btw look at this module's source :)

    I don't see what I'm supposed to get from that. If I'm supposed to
    see the magic (and explanation) be examining the source for the 'this'
    module, well, I don't see how I can do that either. Can someone who
    gets this share a clue?

    Thanks,
    - Joe

    Comment

    • coldpizza

      #3
      Re: 'Hidden Features of Python'

      If you are using and IDE, such as Eclipse, PyScripter, etc, then CTR
      +click on 'this' should do the trick.
      In ipython you can do 'import this' and then type 'this??' Or if you
      are *not* lazy, you could try locating the file in the Python tree.
      import this
      # btw look at this module's source :)
      >
      I don't see what I'm supposed to get from that.  If I'm supposed to  
      see the magic (and explanation) be examining the source for the 'this'  
      module, well, I don't see how I can do that either.  Can someone who  
      gets this share a clue?
      >
      Thanks,
      - Joe

      Comment

      • Joe Strout

        #4
        Re: 'Hidden Features of Python'

        On Oct 17, 2008, at 10:35 AM, coldpizza wrote:
        If you are using and IDE, such as Eclipse, PyScripter, etc, then CTR
        +click on 'this' should do the trick.
        In ipython you can do 'import this' and then type 'this??' Or if you
        are *not* lazy, you could try locating the file in the Python tree.
        Oh! They're actually talking about a module literally called 'this'!
        I thought that was just a placeholder, like "foo".

        Interesting (and useful).

        As for examining the source though, it seems like it could be
        shortened up quite a bit now -- in fact all the source except the
        assignment to s could be replaced with the one-liner

        print s.encode('rot13 ')

        Though the existing source is interesting in its own way too.

        Thanks,
        - Joe


        Comment

        • Kurt Smith

          #5
          Re: 'Hidden Features of Python'

          On Fri, Oct 17, 2008 at 11:48 AM, Joe Strout <joe@strout.net wrote:
          On Oct 17, 2008, at 10:35 AM, coldpizza wrote:
          >
          >If you are using and IDE, such as Eclipse, PyScripter, etc, then CTR
          >+click on 'this' should do the trick.
          >In ipython you can do 'import this' and then type 'this??' Or if you
          >are *not* lazy, you could try locating the file in the Python tree.
          >
          Oh! They're actually talking about a module literally called 'this'! I
          thought that was just a placeholder, like "foo".
          >
          Interesting (and useful).
          >
          As for examining the source though, it seems like it could be shortened up
          quite a bit now -- in fact all the source except the assignment to s could
          be replaced with the one-liner
          >
          print s.encode('rot13 ')
          Methinks you miss the point -- read the Zen, and apply its principles
          to the "this" module. I think they managed to break pretty much all
          of them, probably to illustrate a point, all in good fun. Tim Peters
          rocks!

          For more fun with the Zen, see this thread:



          Best,

          Kurt

          Comment

          • Lawrence D'Oliveiro

            #6
            Re: 'Hidden Features of Python'

            In message <mailman.2598.1 224262418.3487. python-list@python.org >, Kurt Smith
            wrote:
            For more fun with the Zen, see this thread:
            >
            http://mail.python.org/pipermail/pyt...ly/055857.html
            For someone complaining about improperly-spaced punctuation, they can't
            spell "orthographical ". :)

            --
            Lawrence "Skitt's Law? What Skitt's Law?" D'Oliveiro

            Comment

            • Aaron \Castironpi\ Brady

              #7
              Re: 'Hidden Features of Python'

              On Oct 17, 11:00 am, coldpizza <vri...@gmail.c omwrote:
              Having read through the link below I finally managed to grasp some
              concepts that I only read about in the docs but never got to really
              understand. Maybe it will be helpful for people like myself who are
              not yet fully comfortable with some of Python's `hidden' features.
              >
              http://stackoverflow.com/questions/1...ures-of-python
              +1 good link.

              Comment

              Working...