Python module seeing a full list as empty in another module

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-04-12T22:58:09Z Indexed on 2010/04/12 23:02 UTC
Read the original article Hit count: 266

Filed under:
|
|

I'm working on a pygame project and have the main engine layed out. The problem is I hit a bug that I just can not seem to figure out. What happens is one module can't read a variable from another module.

It's not that the variable can't be read, it just sees an empty list instead of what it really is.

Instead of posting the entire source code I reproduced the bug in two small snippets that hopefully a skillful python-ist can interpret in his\her head.

Code: main.py (This is the file that gets run)

import screen

screens = [] #A stack for all the game screens

def current_screen():
    #return a reference to the current screen
    return screens[-1]

def play():
    print'play called'
    current_screen().update()

if __name__=='__main__':
    screens.append(screen.Screen())
    play()

screen.py

import main

class Screen:
    def __init__(self):
        print'screen made'
    def update(self):
        print main.screens
        #Should have a reference to itself in there

Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about import