I've been messign around with Python a little recently. Though I now want to import one of my .py files into my "main" file, but I get an "module" object is not callable error.

How do I actually do this then.

My files:
KeyGenerator.py
main.py

Code I use to import:
import KeyGenerator

It sounds that you are using statement KeyGenerator(....) which does not make sense.

You must use keyGen = KeyGenerator.my_generator_function() If my_generator_function is the function defined in the module KeyGenerator and it does not take any parameters.

Lets say the following is keygenerator.py

def function1():
    print "Helloworld"
    #end function

To call it in main use the following method.

import keygenerator as mykey

#the main program
    mykey.function1()       #this will call the function.

Also remember to place them in the same folder for simpicity.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.