0

I have two classes in the same folder; filename

  • Filename: twisted, class name : Root,method :def render_GET(self, request):
  • Filename: ladpConnector, class name:MyClass, method : getMachines(self)

I want to call getMachines from the first file, inside Root class.

I tried following options;

  • MyClass().getMachines()

from ldapConnector import Myclass

MyClass().getMachines() 

All gives issues, undefined method/undefined variable class Myclass etc..

What is teh right way to call that method?

2
  • 2
    In from ldapConnector import Myclass class name not is same case(MyClass) Commented Oct 17, 2017 at 22:24
  • @SatanDmytro it is right ..here it is typo..Thanks there was another spelling mistake..It works. Commented Oct 17, 2017 at 22:25

2 Answers 2

1

I'm not sure what you are asking, but you need to import that class in the file that has the Root class:

# twisted.py file from ldapConnector import MyClass class Root(): def __init__(self): MyClass().getConnections() 
Sign up to request clarification or add additional context in comments.

2 Comments

I have print statement under MyClass init method also under getMachines(self) method. When I call from Twsited.py like MyClass().getMachines() , i see print from init method, not from getMachines() method.. Means, it is not calling getMachines.What Im doing wrong?
It works thanks..Forgot to annotate @defer.inlineCallbacks in the getMachines ()method
1

To access files within the same module you need to do relative imports: from .ldapConnector import MyClass should work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.