why this error?
Fredrik Lundh
fredrik at pythonware.com
Wed Mar 16 08:54:12 EST 2005
"spencer" <infotechsys at pivot.net> wrote:
> I'm not sure why I can't concatenate dirname() with basename().
>
> Traceback (most recent call last):
> File "showDir.py", line 50, in ?
> print 'somthing new...', os.path.join(os.path.dirname(os.getcwd)) +
> os.path.basename(os.getcwd())
> File "/usr/lib/python2.3/posixpath.py", line 119, in dirname
> return split(p)[0]
> File "/usr/lib/python2.3/posixpath.py", line 77, in split
> i = p.rfind('/') + 1
> AttributeError: 'builtin_function_or_method' object has no attribute
> 'rfind'
you're passing a function (os.getcwd) to dirname, not a directory name.
>>> os.getcwd
<built-in function getcwd>
>>> os.getcwd()
'/home/fredrik'
if you fix that, you get
os.path.join(os.path.dirname(os.getcwd())) + ...
which is the same as
os.path.dirname(os.getcwd()) + ...
maybe you meant
os.path.join(os.path.dirname(os.getcwd()), os.path.basename(os.getcwd()))
?
that's a rather odd way to write:
os.getcwd()
</F>
More information about the Python-list
mailing list