[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Making A Module



You mean for Python in general? Just make a file, put your functions
in there, call it "whatever.py". Keep it in the same directory as your
main python code, and put:

import whatever

That way, to call a function, you say:

whatever.func()



If you don't want to type "whatever" all the time, instead of the
import statement above, say:

from whatever import *

then, to call the same function, just say:

func()

But be careful doing it this way, make sure you don't end up having
multiple functions with the same name when you do this. I personally
usually do the first method, or import individual functions:

from whatever import func1

But it sounds like this is what you were trying to avoid (having a
long list of functions).