I am new to python. I am trying to run following program:
class Temp():
def __init__(self):
print 'hello world!'
def main():
temp = Temp()
print 'here i am'
if __name__ == '__main__':
main()
I am getting this error:
Traceback (most recent call last):
File "test.py", line 1, in <module>
class Temp():
File "test.py", line 11, in Temp
main()
File "test.py", line 7, in main
temp = Temp()
Why i am getting this error?
Unindent
main()and what’s below it, right now it’s a method ofTempnot standalone function. You’re essentially trying to call a method without an instance ofTemp.Indentation is how python determines what is in a method, class, loop or not. See here:
EDIT: