From: Cliff H. <xl...@da...> - 2010-10-06 17:32:14
|
*Err, my indentations were off there, correcting below: * 2010/10/6 Cliff Hill <xl...@da...> > *Another note.... I believe your TestClass wasn't instantiated either... > If memory serves, you'll need to do this:* > * > * > > *#TestModule.py > > class TestClass: > def testMethod(): > print "Hello World" > * > * > #Test.py > from TestModule import TestClass* > * > * > *tc = TestClass() > tc.testMethod()* > > * > * > *If you want to use it the way you did before, simply don't make a method > of a class, write a function into the module, like:* > * > * > * > > #TestModule.py > def testFunction(): > print "Hello World" > > #Test.py > import TestModule > > TestModule.testFunction() > > * > * > * > *It just depends on how you want to use everything.... if you want > objects, then the first version works good, if you just want some simple > functions (somewhat like how Java does things with static methods), then the > latter version works good. You can mix it up too:* > * > * > * > > #TestModule.py > class TestClass: > def testMethod(): > print "I'm a method." > > def testFunction(): > print "I'm a function." > > #Test.py > import TestModule > > TestModule.testFunction() > > tc = TestModule.TestClass() > tc.testMethod() > > * > -- "I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm Website: http://darkhelm.org |