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 test2.py

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

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

from test2 import test

print Test1

but i keep getting this error:

Traceback (most recent call last):
  File "test1.py", 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..
(text2.py)

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

now call text2.py class.
(text1.py)

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

##output
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
;)
thanks

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.