class problem

hi,

i’m new to python but i have a lot of c experience. my problem is that i can’t create a new class in a function. short code with hello world explains it better.

class test:
def helloworld()
print “hello”

testclass=test()
testclass.helloworld()

this runs, but

class test:
def helloworld()
print “hello”

def function():
testclass=test()
testclass.helloworld()

this fails with an syntax error. where is my mistake? thanks

When you define the class test it should be:


class test:
     def helloworld(<b>self</b>):
          print "hello"

If that doesn’t fix the error, then it may be an issue with your indentation. Please post your code in between code tags to help us better help your debugging.

thanks for your reply. this forum is very good by the way.
ahh and the script, i removed all not so important code to test it. and it ran. so i decided to rewrite it and now it runs perfectly. but i still don’t know what was wrong.thx.

I find that python is annoyingly finicky about whitespace. I hate the indent mechanism.