sorry for the noob question.

i'm new to python. i'm trying to learn about classes and def.

i created a simple one here called

class test:
  def Test1(T1):
    T1 =  "this is a test"

i have another python file, which is the main program called

from test2 import test

print Test1

but i keep getting this error:

Traceback (most recent call last):
  File "", line 5, in <module>
    print Test1
NameError: name 'Test1' is not defined

am i doing this correct? can someone help me?

Because text your classs for text2 is wrong.
Try this..

class Text(object): ## object not very important. you can remove that.
   def text(self):
     return("Hello world")

now call class.

from text2 import Text
hello = Text()
print hello.text()

Hello world

Very simple. I think its well explained yea ;)

commented: thanks. this really helped me. +1

thanks. i think i get it now.

You can upvote me a lil and close the thread

Be a part of the DaniWeb community

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