1

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()
2
  • it actually works for me as is, maybe you have some indentation issues on your original source file? Commented Jan 13, 2014 at 9:27
  • Yeah, I found it rather odd too.. No its a straight copy and paste. But you gave me an idea, will if that works :) Commented Jan 13, 2014 at 19:55

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.