import os
import sys
class Corrector:
def correctAll(dir):
print "ok"
c = Corrector()
c.correctAll(os.getcwd())
This code is printing:
TypeError: correctAll() takes exactly
1 argument (2 given)
but AFAIK os.getcwd() returns a single string.. what’s wrong here?
You need to accept
selfas an argument or use thestaticmethoddecorator.or
The distinction between the two is if you want the method to have access to the instance that it’s called on or not. If so, then use the first one and the the instance will be available as
self. Otherwise, you can use the second one.Python methods work by explicitly accepting the object that they are bound to as their first argument (
selfis canonical here but it can really be anything). That argument is then implicitly passed when a call occurs.