Home > OS >  `TypeError: missing 1 required positional argument: 'self'` Whitebox tools
`TypeError: missing 1 required positional argument: 'self'` Whitebox tools

Time:01-21

I am attempting to use whitebox geospatial tools to analyze .tif files. Any whitebox tool I run however, raises the error: TypeError: missing 1 required positional argument: 'self'. I understand that this is a well-documented error within the stack overflow community, however, the way I understand the self argument, it is used in the creation of a class, which I am not doing as far as I can tell.

Additionally, upon the addition of the argument in an attempt to resolve the issue as various other stack answers have suggested, I receive a name error, stating that 'self' is not defined. Both cases are exemplified bellow.

Code:

from whitebox_tools import WhiteboxTools as wbt

print(wbt.list_tools())

Result:

TypeError: list_tools() missing 1 required positional argument: 'self'

Code (self argument added):

print(wbt.list_tools(self))

Result:

NameError: name 'self' is not defined

Please excuse my lack of understanding of the self argument. It stems from a further lack of understanding of Python classes. Either way, any resolution to this problem I can find has been to add the self argument which does not seem to work in this case.

Thank you for considering.

CodePudding user response:

"TypeError: missing 1 required positional argument: 'self'" generally tends to mean you're attempting to call an instance method directly on a class.

WhiteboxTools looks like a class. You're importing it with an alias that makes it look like an instance, and attempting to use it as one.

Don't do that, but just instantiate an object of that class:

from whitebox_tools import WhiteboxTools

wbt = WhiteboxTools()

print(wbt.list_tools())
  • Related