How To Uses Modules And Plugins

Lie Lie.1296 at gmail.com
Sun Apr 6 13:49:42 EDT 2008


On Apr 7, 12:28 am, mar... at everautumn.com wrote:
> I am working on a client/server, computer role-play game using Python.
> I want to gradually expand the game world by creating maps as
> individual py files in a map directory. I am a little foggy of how to
> do this. I have read about the __import__() function. I want to
> understand what the difference is between using modules and plugins.
> Are they the same thing? How will my root script interact with the
> individual modules once it has loaded them? If you can point me to a
> web site or tutorial on this subject I would be thankful.

I think you're doing it with the wrong approach, a map is a data so it
should not be placed in a .py file, instead it should be placed in
something like .map files which is read by your program to generate
the map object. To read a file in python, use:

f = file('path/path/file.map', 'r') # for reading
g = file('path/path/file.map', 'rw') # for read and write

m = f.readline() # To read until meeting a '\n'
n = f.read() # To read until EOF (End of File)
for line in g:
    #
    # To read the file line by line
    # using the very convenient for
    #

f.close() # Don't forget to close the file after use
g.close()




More information about the Python-list mailing list