Hi I'm very new to Python Language, I'm getting this error "AttributeError: 'str' object has no attribute 'internalSplit'" and don't understand why.
please check the following code..

sourceAction = str(sourceAction);
            identityInfoDict = dict(identityInfo);
            for key in identityInfoDict.keys():
                if(key.find("GENESYS_DATA") >= 0):
                     intDict = self.internalSplit(key,identityInfoDict)

and the internalSplit is a function with in the same module

def internalSplit(self,dictKey,identityInfoDict):
        dictKeyWords = dictKey.split(".")
        internalDict = []
        if (dictKeyWords.__len__()>2):
            seq = (dictKeyWords[0], dictKeyWords[2]); 
            dictKeyWords = ".".join( seq );
        elif (dictKeyWords.__len__()>1):
            dictKeyWords = dictKey;
        internalDict[dictKeyWords] = identityInfoDict.key(dictKey)
        return internalDict

What is the problem and why it is giving? Please help me

You have functions like class definition with self but you are speaking of module. Could you post whole class please. Or better still some pseudo code of what you want to do and accomplish.

thanks for reply

I've a module and a class definition in the module, class has two functions, in one function I call "internalSplit(...)" function, here is the code below for a module

class RegistryReconHandler:

 def __init__(self):
        '''        
        '''

 def internalSplit(self,dictKey,identityInfoDict):
        dictKeyWords = dictKey.split(".")
        internalDict = []
        if (dictKeyWords.__len__()>2):
            seq = (dictKeyWords[0], dictKeyWords[2]); 
            dictKeyWords = ".".join( seq );
        elif (dictKeyWords.__len__()>1):
            dictKeyWords = dictKey;
        internalDict[dictKeyWords] = identityInfoDict.key(dictKey)
        return internalDict
    
  def processAction(self, sourceAction, identityInfo):
      
      try:
          sourceAction = str(sourceAction);
          identityInfoDict = dict(identityInfo);
          for key in identityInfoDict.keys():
              if(key.find("GENESYS_DATA") >= 0):
                   intDict = self.internalSplit(key,identityInfoDict)
                   inDict = dict(intDict)
                   print "keys",inDict.keys()
      except Exception:
          raise ;
      return 0;

But where is the init code? Code does not set any attributes. Why are functions inside class?

Have you any use case, for example.

but in my code there are no attributes, do we need them to call a function ? please suggest..
generally functions are declared inside classes, and I think python also does this.

I never use any use case, could you please explain little bit..

eventually please suggest in that code how to avoid that error

it says str object, which means it's intepreting the self as a string.

print it out and see what it say.

Also you don't need to declare functions in a class. Python does not enforce object oriented programming, it encourages object oriented programming.

In reality Python is closer to procedural based programming.

well finally I accomplish this.. here is the process I made

I declare internalSplit(..) as __internalSplit(..) and call that function and use that function in another function like splitDictKey = self.__internalSplit(dictKey)

from out side I call the function like the following

handler = IDMRegistryReconHandler()    
key = handler._IDMRegistryReconHandler__internalSplit('BLOCK_1.GENESYS_DATA.GENESYS_EMP_TYPE')    
print key;

i.e. I create object with the reference handler and call that function like above.. in that way i solve that issue and working..
uh.. big difference in java and python.. I feel only

Anyway thanks for your help on this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.