Harshana Nanayakkara
Harshana Nanayakkara

Reputation: 184

Python AttributeError instance has no attribute, When I add a new method.

I am Trying to call a another method within my class, for some reason I am getting the AttributeError: portfinder instance has no attribute 'generatePortNumber' See my code below:

when I tried to call the generatePortNumber I'm getting the same error. I have never come across this issue.

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sqlite3 as lite
import sys
import random



class portfinder:
    """docstring for ClassName"""
    def __init__(self):
        self.portsToCheck = ['agentport','BatchProcessingAgentPort','databaseport','indexserviceport','monitorport','servicefacadeport','webdriverport']
        self.dataBasePort = (u'60025',)
        self.portInUse = False 
        self.x = 0



    def generatePortNumber(self):
            self.newPortNumber = random.randrange(8000, 9000)
            print self.newPortNumber
            return self.newPortNumber

    def findUsedPortsinDB(self):
        con = lite.connect('D:\play\Opes\db.sqlite3')
        with con:    
            cur = con.cursor()
            sqlStatement = "Select " + self.portsToCheck[2] +' From Jobs_jobs'
            print sqlStatement
            cur.execute(sqlStatement)
            rows = cur.fetchall()
            for row in rows:
                print row 
                if row == self.dataBasePort:
                    self.portInUse = "true"
                    self.generatePortNumber()                   





if __name__ == "__main__":
    m = portfinder()
    m.findUsedPortsinDB()

Upvotes: 1

Views: 11351

Answers (1)

Harshana Nanayakkara
Harshana Nanayakkara

Reputation: 184

Found what was wrong I had a extra indentation in my method

Upvotes: 5

Related Questions