A comp.lang.python code snippet archive?

qneill at my-deja.com qneill at my-deja.com
Fri Mar 10 11:43:13 EST 2000


In article <000601bf829b$dd53c660$3acbd9c2 at peridot.optichrome.com>,
  "Adrian Eyre" <a.eyre at optichrome.com> wrote:
> >>  * if it's still worthwile to continue this site

Let me throw in my 2c worth - yes it is worthwhile! Thanks.

> We could also have some convention about Python snippets
> posted to c.l.py,
> so they can be automagically extracted and categorised.
>
> e.g.
>
> #snippet "mysnippet.py"
> #category "Networking"
> #description "This does something interesting"
> #begin
> #!/usr/bin/env python
>
> my_code_here()
>
> #end

I was thinking along the same lines, invent a simple markup language
that facilitiates snippet harvesting.  Then, early on, you can just
repost (with permission) snippets with the markup included.  Later, if
the community likes the idea, people would probably post with the markup
the first time, and a new posting protocol develops itself.

How about this as an example.  Here is some stuff that appears in alot
of my scripts:

import os
import sys
HOME=os.path.dirname(sys.argv[0])
ME = os.path.basename(sys.argv[0])

def usage(msg=None):
    global ME
    if msg is not None:
        print msg
    print '%s -x <opts here>' % ME
    sys.exit(1)

Here is what the snippet would look like reposted with the markup.  The
SNIPPET scraper would know how to throw away the quote marks '>':

<SNIPPET
  name="Program Preamble and Usage"
  language=python
  level=function
  category="misc"
  description="typical usage"
  tested=compiles>

> import os
> import sys
> HOME=os.path.dirname(sys.argv[0])
> ME = os.path.basename(sys.argv[0])
>
> def usage(msg=None):
>    global ME
>    if msg is not None:
>        print msg
>    print '%s -x <opts here>' % ME
>    sys.exit(1)

</SNIPPET>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list