jonalv
jonalv

Reputation: 6116

os.path.basename(path) what does "AttributeError: 'unicode' object has no attribute 'path'" mean?

I am trying to use os.path.basename(path) on a string. I thought that was how it was used. In the doc for version 3 it clearly says that is the case but I am using 2.7. How do I use the method if all I have is a string (which clearly don't have a path attribute?)

Upvotes: 0

Views: 1313

Answers (1)

Reut Sharabani
Reut Sharabani

Reputation: 31339

You probably have overridden os with your own variable.

Something like this:

import os
# ...
os = "abc"
# ...
os.path # <-- error

Make sure you don't shadow imported libraries.

Upvotes: 2

Related Questions