-2

here is my code:

my file which I start:

 from SQLhandler import SQLhandler 
 D = SQLhandler.loadProject(4711)

a part of my SQLhandler file:

class SQLhandler(object):
   db = pymysql.connect(... )

   def loadProject(self, project_id):
    #do some stuff

I want to use db in other functions, so I put it on the class level and added a "self" to loadProject. Now the second line in my start file throws an error:

"loadProject() missing 1 required positional argument: 'project_id'"

What's wrong with my code?

theother
  • 307
  • 2
  • 16
  • 2
    `self` is the instance of `SQLhandler` that `loadProject()` is being called from. In your example, you are not creating an instance, so the first argument (which is expected to be `self`), is being assigned from `4711`, and then there is no `project_id`. Perhaps you meant: `D = SQLhandler().loadProject(4711)`. – John Anderson Nov 09 '18 at 00:46

1 Answers1

0

Within your class definition you need to have a def __init__(self, ... params): function that tells how to initialize a new instance. Try including something along the lines of

def __init__(self, project_id):
    self.project_id = project_id
John Meade
  • 142
  • 6