Python Code Snippets

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aurélien Géron

    Python Code Snippets

    Hi,

    Does anyone know where I can find a lot of Python code snippets?

    I searched the Python wiki and Internet but could not find more than five or
    ten code snippets at a time.

    I'm looking for a kind of organized list (GUI snippets, database access
    snippets, I/O snippets, etc.). I find that there's no better way to learn a
    language than to be able to cut&paste actual working bits of code.

    Thanks,
    Aurélien


  • Guyon Morée

    #2
    Re: Python Code Snippets

    You're gonna love this :)

    Community support for users of the ActiveState Platform.



    "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote in message
    news:be1hs0$111 s$1@biggoron.ne rim.net...[color=blue]
    > Hi,
    >
    > Does anyone know where I can find a lot of Python code snippets?
    >
    > I searched the Python wiki and Internet but could not find more than five[/color]
    or[color=blue]
    > ten code snippets at a time.
    >
    > I'm looking for a kind of organized list (GUI snippets, database access
    > snippets, I/O snippets, etc.). I find that there's no better way to learn[/color]
    a[color=blue]
    > language than to be able to cut&paste actual working bits of code.
    >
    > Thanks,
    > Aurélien
    >
    >[/color]


    Comment

    • Behrang Dadsetan

      #3
      Re: Python Code Snippets

      Guyon Morée wrote:[color=blue]
      > You're gonna love this :)
      >
      > http://aspn.activestate.com/ASPN/Cookbook/Python
      >
      >
      > "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote in message
      > news:be1hs0$111 s$1@biggoron.ne rim.net...
      >[color=green]
      >>Hi,
      >>
      >>Does anyone know where I can find a lot of Python code snippets?
      >>[/color][/color]

      Or you might want to just look around here. In this
      newsgroup/mailing-list one gets to see really lots of nice code.

      One that I would nominate as the best test for measuring a hard-core
      python programmer would be to explain the following code without the
      context :)

      Karl Scalet wrote:[color=blue]
      > there are very likely easier ways, but at least
      >
      > s = 'C6 H12 O6'
      > print [' '.join(xx) for xx in apply(
      > zip,[(x[0],x[1:]) for x in s.split()])]
      >
      > gives some results,
      >
      > Karl[/color]

      Once I understood the above, I beleive I will write python in my Resume...

      What was this about "One simple obvious way doing it"? ;)

      Comment

      • Aurélien Géron

        #4
        Re: Python Code Snippets

        Hey thanks !
        I wish it had a better ordering than just a list, but it's full of good
        stuff.

        Aurélien

        "Guyon Morée" <gumuz@looze.ne t> a écrit dans le message de
        news:3f044c20$0 $8303$4d4ebb8e@ news.nl.uu.net. ..[color=blue]
        > You're gonna love this :)
        >
        > http://aspn.activestate.com/ASPN/Cookbook/Python
        >
        >
        > "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote in message
        > news:be1hs0$111 s$1@biggoron.ne rim.net...[color=green]
        > > Hi,
        > >
        > > Does anyone know where I can find a lot of Python code snippets?
        > >
        > > I searched the Python wiki and Internet but could not find more than[/color][/color]
        five[color=blue]
        > or[color=green]
        > > ten code snippets at a time.
        > >
        > > I'm looking for a kind of organized list (GUI snippets, database access
        > > snippets, I/O snippets, etc.). I find that there's no better way to[/color][/color]
        learn[color=blue]
        > a[color=green]
        > > language than to be able to cut&paste actual working bits of code.
        > >
        > > Thanks,
        > > Aurélien
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Skip Montanaro

          #5
          Re: Python Code Snippets


          Aurélien> I wish it had a better ordering than just a list, but it's
          Aurélien> full of good stuff.

          You can always buy the book. It has both an index and a table of contents.

          Skip

          Comment

          • rzed

            #6
            Re: Python Code Snippets

            Behrang Dadsetan wrote:[color=blue]
            > Guyon Morée wrote:[color=green]
            >> You're gonna love this :)
            >>
            >> http://aspn.activestate.com/ASPN/Cookbook/Python
            >>
            >>
            >> "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote in message
            >> news:be1hs0$111 s$1@biggoron.ne rim.net...
            >>[color=darkred]
            >>> Hi,
            >>>
            >>> Does anyone know where I can find a lot of Python code snippets?
            >>>[/color][/color]
            >
            > Or you might want to just look around here. In this
            > newsgroup/mailing-list one gets to see really lots of nice code.
            >
            > One that I would nominate as the best test for measuring a hard-core
            > python programmer would be to explain the following code without the
            > context :)
            >
            > Karl Scalet wrote:[color=green]
            > > there are very likely easier ways, but at least
            > >
            > > s = 'C6 H12 O6'
            > > print [' '.join(xx) for xx in apply(
            > > zip,[(x[0],x[1:]) for x in s.split()])]
            > >
            > > gives some results,
            > >
            > > Karl[/color]
            >
            > Once I understood the above, I beleive I will write python in my
            > Resume...
            >
            > What was this about "One simple obvious way doing it"? ;)[/color]

            Obviously, this is just what people mean by "syntactic sugar."

            --
            rzed





            Comment

            • Mickel Grönroos

              #7
              Re: Python Code Snippets

              On Thu, 3 Jul 2003, Aurélien Géron wrote:
              [color=blue]
              > Does anyone know where I can find a lot of Python code snippets?[/color]

              Try:



              Cheers,

              /Mickel

              --
              Mickel Grönroos, application specialist, linguistics, Research support, CSC
              PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
              CSC is the Finnish IT center for science, www.csc.fi


              Comment

              • Paul Simmonds

                #8
                Re: Python Code Snippets

                "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> wrote in message news:<be1hs0$11 1s$1@biggoron.n erim.net>...[color=blue]
                > Hi,
                >
                > Does anyone know where I can find a lot of Python code snippets?[/color]
                <snip>[color=blue]
                > I'm looking for a kind of organized list (GUI snippets, database access
                > snippets, I/O snippets, etc.). I find that there's no better way to learn a
                > language than to be able to cut&paste actual working bits of code.[/color]
                <snip>
                Hi,
                As well as the excellent resources others have mentioned, I'd
                definately recommend investigating the Python source distribution, if
                you haven't already. The joy of working with an Open Source language
                is that there's no problem if you want to look at some decent code:

                The Lib and Demo directories provide examples from the simple to the
                not-so-simple in a variety of application domains.

                The Objects and Include directories provide good examples of using the
                Python-C API. Seeing how the objects are created under the hood has
                increased my understanding of how Python works, and the quality of my
                C extensions.

                I'd also say the online Cookbook has a reasonable search facility, and
                lists of recipies from different areas, so it is relatively easy to
                find a particular code snippet.

                HTH,
                Paul

                Comment

                • Bernard Delmée

                  #9
                  Re: Python Code Snippets

                  > Aurélien> I wish it had a better ordering than just a list, but[color=blue]
                  > it's Aurélien> full of good stuff.
                  >
                  > You can always buy the book. It has both an index and a table of
                  > contents.[/color]

                  IMO not ideally suited to learning the language, but an
                  invaluable compendium of idioms and advanced topics

                  Sample chapter available at


                  Other multi-language code samples repositories I know of:
                  Free, secure and fast downloads from the largest Open Source applications and software directory - SourceForge.net

                  and


                  CHeers,

                  Bernard.



                  Comment

                  • John J. Lee

                    #10
                    Re: Python Code Snippets

                    "Aurélien Géron" <ageron@HOHOHOH Ovideotron.ca> writes:
                    [color=blue]
                    > Does anyone know where I can find a lot of Python code snippets?[/color]
                    [...]



                    They're working on useless 2, with categories.


                    John

                    Comment

                    • Stephen Ferg

                      #11
                      Re: Python Code Snippets


                      Comment

                      • Cameron Laird

                        #12
                        Re: Python Code Snippets

                        In article <be1hs0$111s$1@ biggoron.nerim. net>,
                        Aurélien Géron <ageron@HOHOHOH Ovideotron.ca> wrote:[color=blue]
                        >Hi,
                        >
                        >Does anyone know where I can find a lot of Python code snippets?
                        >
                        >I searched the Python wiki and Internet but could not find more than five or
                        >ten code snippets at a time.
                        >
                        >I'm looking for a kind of organized list (GUI snippets, database access
                        >snippets, I/O snippets, etc.). I find that there's no better way to learn a
                        >language than to be able to cut&paste actual working bits of code.[/color]

                        Comment

                        Working...