0

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

3
Contributors
5
Replies
25
Views
2 Years
Discussion Span
Last Post by MasterHacker110
1

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

1

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.

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.