0

I'm pretty new to Python and, in writing an app, have ended up with a structure that's a bit of a mess. The example below should illustrate what I'm trying to do. The issue is that I can't call the login method from common.py because it is only defined in website1.py or website2.py.

Module common.py

class Browser():
 def load_page():
 Login.login()

Module website1.py import common.py

class Login:
 @staticmethod 
 def login():
 #code to login to this website 1

Module website2.py import common.py

@staticmethod
class Login:
 def login():
 #code to login to website 2

Any thoughts on how to restructure this would be appreciated.

asked Jun 9, 2011 at 18:12

1 Answer 1

1

First of all, why static methods? You could just do def login at the global level.

Second of all, you could pass a class reference to the Browser class. (or a module reference if you take my first suggestion)

class Browser(object):
 def __init__(self, loginCls):
 self.loginCls = loginCls
 def login_page(self):
 self.loginCls.login()
answered Jun 9, 2011 at 18:18
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.