0

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?

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by richieking
1

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 ;)

Edited by richieking: n/a

Votes + Comments
thanks. this really helped me.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.