Is it possible to check for global variables in IPython when running a file?
Question: I have a file like so:

    
    
    import pandas a pd
    
    def a_func():
        print 'doing stuff'
    
    if __name__ == "__main__":
        if 'data' not in globals():
            print 'loading data...'
            data = pd.read_csv('datafile.csv')
    

When I run the file in IPython with `run file.py`, it always loads the data,
but when I print `globals.keys()` in IPython, I can see the `data` variable.
Is there a way to access the global variables from IPython from within my
`file.py` script, so I don't have to load the data every time I run the script
in IPython?


Answer: Everytime a python file is executed the globals() dictionary is reset by the
interpreter. So if you will try to do something like

    
    
    print globals().keys()
    

you can see that 'data' is not in globals. This dictionary gets updated as the
program runs. So I don't think you can refer to the globals() of the IPython
in the program.

check this [link](https://docs.python.org/2/faq/programming.html#how-can-i-
have-modules-that-mutually-import-each-other) ,according to it, globals are
emptied.

