Re: How do I install libxml2 and libxslt?

2009-11-02 Thread Nat Williams
On Mon, Nov 2, 2009 at 9:41 AM, Kevin Ar18  wrote:

>  I want to use the lxml library, but can't get it to work on Windows.
>
> The following will not work:
> * import libxml2
> * import libxslt
> * from lxml import etree
>
> Here's the instructions:
> http://codespeak.net/lxml/installation.html
>
> * So, I run "easy_install lxml" -- that works!
> * Now, it says I need to install libxml2 and libxslt... how do I do that?
> ...so, I download the libxml2 and libxslt pre-built Windows binaries here:
> http://www.zlatkovic.com/pub/libxml/
> Now what do I do with them?
> I opened the zip files and copied the bin directories to Python\Lib ...
> like this: Python\Lib\libxml2\libxml2.dll ... that doesn't work. I copy just
> dll to Python\DLLs ... that doesn't work.
>
> What now?
>

According to the lxml installation instructions you linked, the windows lxml
binary is statically linked and you do not need to install the libraries
separately.  If 'from lxml import etree' works, then you're done.

libxml2 and libxslt are C libraries, not things that you can or would
import.  The joy of lxml is not having to deal with those libraries on your
own.

Nat
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheriting dictionary

2009-08-18 Thread Nat Williams
On Tue, Aug 18, 2009 at 2:44 PM, Pavel Panchekha wrote:

> I want a dictionary that will transparently "inherit" from a parent
> dictionary. So, for example:
>
> """
> a = InheritDict({1: "one", 2: "two", 4: "four"})
> b = InheritDict({3: "three", 4: "foobar"}, inherit_from=a)
>
> a[1] # "one"
> a[4] # "four"
> b[1] # "one"
> b[3] # "three"
> b[4] # "foobar"
> """
>
> I've written something like this in Python already, but I'm wondering
> if something like this already exists, preferably written in C, for
> speed.


Why complicate this with a custom object?  Just use regular dicts and make b
a copy of a.

a = {1: 'one', 2: 'two', 4: 'four'}
b = dict(a)
b[3] = 'three'
b[4] = 'foobar'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie Question regarding __init__()

2009-07-31 Thread Nat Williams
As MRAB described, ALL instance methods need to accept 'self' as a first
parameter, as that will be passed to them implicitly when they are called.
This includes __init__.  The name 'self' is just a commonly accepted
convention for the name of the instance object passed to methods.  You don't
have to call it that, but you really should.

Take a look at http://docs.python.org/tutorial/classes.html#class-objects
It might help shed some light on how methods and instances work.

One other thing.  I'm a little confused by the first line of
dcObject.__init__:

self.init_Pre() and self.init_Exec()

I suspect this does not do what you think it does.  init_Pre and init_Exec
will both be called by this expression (unless init_Pre throws an exception,
of course).  You're not getting anything here that you wouldn't by just
calling each method on a separate line, except just making it harder to
read.

Nat


On Fri, Jul 31, 2009 at 8:53 PM, Simon  wrote:

> Hi
>
> So should the dcObject class include the "self" as well since I have
> not defined an __init__ method in dcCursor?
>
> Simon
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list