[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] How to export a function to a module or script



Leonardo Santagada wrote:
> 	It isn't a problem directly related to pygame, but I'm making
 > a game and I was having this problem. I need to call a script from my
> main program and I want it to use some function from the main one. What
 > I think I need is some way to export some functions to a python script
 > that I call from the main program. Does someone knows how to do that?

if i'm understanding this is just using the python "import".
you can import any python file and access all of its globals..

import mymodule
mymodule.myfunction()

if you are talking about a secondary module calling functions that are 
available in the main module things get a little trickier. this is a 
'circular import'. you'll probably need to move the "common" functions from 
the main module into a third module. sometimes this isn't easy to do. 
sometimes the only way around tricky circular imports is to redesign things 
a little.

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org