Problems trying to override __str__ on path class

Mike Krell no at
Mon Oct 23 04:33:49 CEST 2006

Peter Otten <__peter__ at> wrote in
news:ehggfk$60i$00$1 at 
> I get
> np: "overridden __str__: c:/mbk/test"
> str(np): "overridden __str__: c:/mbk/test"
> overridden __str__: overridden __str__: c:/mbk/test/appendtest

Hmmm.  I guess you're not running under windows, since normpath() 
converts / to \ on windows.  I wonder if that's part of the problem.

> Are you using the latest version of the path module?

My says it's 2.1, which is the latest according to the site.

 Older versions
> implied a Path() call in the __div__() operator which would explain at
> least the output you get for
> print np / 'appendtest'

You've lost me here.  What do you mean about "implied a Path() call"?  
Here is the definition of __div__ from

    # The / operator joins paths.
    def __div__(self, rel):
        """ fp.__div__(rel) == fp / rel == fp.joinpath(rel)

        Join two path components, adding a separator character if
        return self.__class__(os.path.join(self, rel))

I still don't understand the TypeError in the delegation case.


More information about the Python-list mailing list