Calling from a parent file in python

Posted by Teifion on Stack Overflow See other posts from Stack Overflow or by Teifion
Published on 2008-12-31T19:14:59Z Indexed on 2010/04/05 23:13 UTC
Read the original article Hit count: 172

Filed under:

I have a file called main.py and a file called classes.py

main.py contains the application and what's happening while class.py contains some classes.

main.py has the following code

main.py

import classes

def addItem(text):
    print text

myClass = classes.ExampleClass()

And then we have classes.py

classes.py

class ExampleClass (object):
    def __init__(self):
        addItem('bob')

Surprisingly enough that's not the actual code I am using because I've stripped out anything that'd get in the way of you seeing what I want to do. I want to be able to call a method that's defined in main.py from a class within classes.py. How do I do this?

Thanks in advance

© Stack Overflow or respective owner

Related posts about python