Yeah, just putting it in a module is easy enough.

filename: config.py

Then in each module you can just do...

# file1.py
import config
config.mutated = 1


#file2.py
import config
x = config.mutated


#file3.py
import file1
import file2

print (file2.mutated) # should print 1





On Fri, Dec 2, 2011 at 4:15 PM, Sean Wolfe <ether....@gmail.com> wrote:

> Hey everybody,
>
> Upon initialization I'd like to set an assets path, which will be
> different depending on platform. I'd like to set it one time upon
> startup, and then have every module import it automatically with the
> changed value. However since modules are loaded once and persisted in
> their original state, I can't get the new value in the new module,
> even if I reload(settings) .
>
> The best option I can think of is actually creating a new module as a
> new file, then importing that new module in every subsequent piece
> that needs it. But I was hoping to do something a little more elegant
> than that. Do we have any sort of application-level variables which
> are muteable? Like an application-level memory space?
>
>
> ----------
> main.py:
> import settings
>
> if android:
>    settings.assets = './assets'
> else:
>    settings.assets = 'c:/my/sources/in/development/bla/bla'
>
>
> then in a future module something like this:
>
> ----------
> gameloop.py:
> import settings
>
> ASSETS_DIRECTORY = settings.assets
> player_img = pygame.image.load(ASSETS_DIRECTORY + 'player.png')
>
>
>
>
> --
> A musician must make music, an artist must paint, a poet must write,
> if he is to be ultimately at peace with himself.
> - Abraham Maslow
>

Reply via email to