Skip to main content

harry palmer's Library tagged python   View Popular

23 Nov 09

Python v2.5 and v2.6 together on openSUSE 11.1 - openSUSE Forums

  • O.k. - I got it



    This is what I did:



    1) Downloaded the Python 2.5.4 source from the python website

    2) Extracted the source and read the readme

    3) used

    Quote:




    ./configure --enable-shared



    4) used

    Quote:




    make



    5) used

    Quote:




    make altinstall



    doing this kept my original 2.6 version the system default.
25 Apr 09

The CherryPy Documentation

  • 3.3.2.10. cherrypy.request.processRequestBody

    This attribute specifies whether or not the request's body (request.rfile, which is
    POST or PUT data) will be handled by CherryPy. If True (the default for POST and PUT
    requests), then request.rfile will be consumed by CherryPy (and unreadable after that).
    If the request Content-Type is "application/x-www-form-urlencoded", then the rfile will
    be parsed and placed into request.params; otherwise, it will be available in
    request.body. If cherrypy.request.processRequestBody is False, then the rfile is not
    consumed, but will be readable by the exposed method.

16 Apr 09

How to get class's name on runtime?

  • Andrew McNamara wrote:
    >
    > >How can I get class-instances name at runtime?
    > >
    > >I have tried to use __name__ method, but that does not exist...
    >
    > Is this what you want: "self.__class__.__name__"?
    >
    > --
    > Andrew McNamara, Senior Developer, Object Craft
27 Mar 09

Toast Driven - Simple Web Scraping

  • Scrape!



    For an example, let's say you want a list of popular/anticipated DVD releases for the week. The website VideoETA features a very comprehensive list of new releases each week. However, their RSS feed is only news, not the releases themselves. So we'll scrape their listings for what we need. Here's the code:

17 Mar 09

RssLibraries - PythonInfo Wiki

  • 1 import feedparser
    2
    3 python_wiki_rss_url = "http://www.python.org/cgi-bin/moinmoin/" \
    "RecentChanges?action=rss_rc"

    4
    5 feed = feedparser.parse( python_wiki_rss_url )

What does 'self' refer to in a @classmethod? - Stack Overflow

  • I thought I was starting to get a grip on "the Python way" of programming. Methods of a class accept self as the first parameter to refer to the instance of the class whose context the method is being called in. The @classmethod decorator refers to a method whose functionality is associated with the class, but which doesn't reference a specific instance.
14 Feb 09

SelectResults: Using Queries

  • Cloning Methods


    These methods return a modified copy of the SelectResult instance
    they are called on, so successive calls can chained, eg
    results = MyClass.selectBy(city='Boston').filter(MyClass.q.commute_distance>10).orderBy('vehicle_mileage')
    or used independently later on.



    orderBy(column)


    Takes a string column name (optionally prefixed with '-' for DESCending)
    or a SQLBuilder expression.



Aegisub: If programming languages were religions...

14 Dec 08

Displaying error message in a try except?

  • >>> import sys, traceback
    >>> try:
    ... 1/0
    ... except:
    ... print sys.exc_info()[0]
    ... print sys.exc_info()[1]
    ... print "LINE=",traceback.tb_lineno(sys.exc_info()[2])
    ...
    exceptions.ZeroDivisionError
    integer division or modulo by zero
    LINE= 2
08 Dec 08

Beautiful Soup documentation

  • Beautiful
    Soup
    is an HTML/XML parser for Python that can turn even invalid
    markup into a parse tree. It provides simple, idiomatic ways of
    navigating, searching, and modifying the parse tree. It commonly saves
    programmers hours or days of work. There's also a Ruby port called Rubyful Soup.

    This document illustrates all major features of Beautiful Soup
    version 3.0, with examples. It shows you what the library is good for,
    how it works, how to use it, how to make it do what you want, and what
    to do when it violates your expectations.

30 Nov 08

By airportyh

  • When you use Python optional arguments you should know that the default value you set is static, it is set at the time the function is defined, and does not change after that. If you a mutable type as the default value, you need to be careful.
    Ex:

    >>> def enlist(n, lst=[]):
    ...   lst.append(n)
    ...   return lst
    ...
    >>> enlist(3)
    [3]
    >>> enlist(4)
    [3, 4]
    >>> enlist(5)
    [3, 4, 5]
    >>> enlist(6)
    [3, 4, 5, 6]

10 Nov 08

PyPy Status Blog: Porting the JIT to CLI (part 2)

  • PyPy JIT for dummies


    As you surely know, the key idea of PyPy is that we are too lazy to write a
    JIT of our own: so, instead of passing nights writing a JIT, we pass years
    coding a JIT generator that writes the JIT for us :-).


    I'm not going to explain how the JIT generator does its job, (perhaps this
    will be the subject of another blog post), but how the generated JIT
    works.


    There are values that, if known at compile-time (i.e., when the JIT compiler
    runs), let the JIT to produce very efficient code. In a dynamic language,
    types are the primary example: for instance, suppose you are a compiler and
    you have to compile to following Python function:


    def mysum(a):
    return a + 1

    At compile time, you don't have any knowledge about the type of the parameter:
    it could be integer, float, an user defined object, etc. In this situation,
    the only safe choice is to emit code which does the usual, slow, full lookup
    to know how to perform the operations.


    On the other hand, suppose that you knew in advance that the parameter is an
    integer: this time, you could emit code that exploits this extra
    knowledge
    , by performing directly a fast integer addition.


    The idea behind PyPy JIT is that if you don't have enough knowledge to
    generate efficient code, you stop compiling and wait until you know
    exactly what you need. Concretely, you emit code that runs until the point
    where you stopped the compilation, then it triggers a special procedure that
    restarts the compiler. This time the JIT compiler knows everything
    you need, because you can inspect the state of the running program.


    Let's see an example: the first time the JIT compiles mysum, it produces
    something like this pseudo-code:

Vim customization for python | cmdln.org (a sysadmin blog)




  • 18th October


    2008



    written by Nick Anderson


    Python seems to keep growing on me. By no means am I a Python master, nor am I a vim guru but I do prefer to use vim over a gui editor. Sure there are some niceties with using a gui but getting comfortable using a tool that is almost always at your disposal has something to be said for it. Adding a few things to your vim environment will make writing python much more pleasurable.


    First there is the python indent plugin. At the time of this writing the current version is 0.3. There is one annoying thing about it. When commenting with hashes it un-indents. Luckily Henry Prêcheu pointed out that its an easy one line fix.

31 Oct 08

Can you list the keyword arguments a Python function receives? - Stack Overflow

  • have a dict, which I need to pass key/values as keyword arguments.. For example..



    d_args = {'kw1': 'value1', 'kw2': 'value2'}
    example
    (**d_args)


    This works fine, but if there are values in the d_args dict that are not accepted by the example function, it obviously dies.. Say, if the example function is defined as def example(kw2):



    This is a problem since I don't control either the generation of the d_args, or the example function.. They both come from external modules, and example only accepts some of the keyword-arguments from the dict..



    Ideally I would just do

1 - 20 of 75 Next › Last »
Showing 20 items per page

Highlighter, Sticky notes, Tagging, Groups and Network: integrated suite dramatically boosting research productivity. Learn more »

Join Diigo