views:

1394

answers:

5

Hello, i have class

class SomeClass:
  def __init__(self):
      self.SomeFunction()
  def SomeFunction(self):
     try:
        self.something = 5
     except:
        print 'error'
     print self.something

tempObject = SomeClass()

And the last string occurs an error:

AttributeError: something

Why?

+1  A: 

You need to post more code. This self-contained example works for me:

class SomeClass:
  def SomeFunction(self):
     try:
        self.something = 5
     except:
        print 'error'
     print self.something

some_object = SomeClass()
some_object.SomeFunction()   # Prints 5
RichieHindle
Ditto, ran exactly the text that is currently in the question and it worked fine.
Dave Costa
+2  A: 

Python is case sensitive. You have:

self.someFunction()

with a small 's', but:

def SomeFunction(self):

with a big 'S'.

RichieHindle
i've got this error durin code typing. Sorry. In real code all is right.
Ockonal
Please use copy-and-paste to post a complete example of the problem. When I fix the case-sensitivity issue, your updated code works perfectly for me.
RichieHindle
A: 

This is perfectly working:

class SomeClass:
  def __init__(self):
      self.SomeFunction()
  def SomeFunction(self):
     try:
        self.something = 5
     except:
        print 'error'
     print self.something

tempObject = SomeClass()

My guess is that you have miss-typed an identifier.

Nadia Alramli
A: 

You can refer following code with intentional bug to generate Attribute error http://fullchipdesign.com/pyerr4.htm and a fixed code

fcd
A: 

Are you using the latest version of python? I had this issue when I tried with an old version. Try updating.

karthrags