I can't seem to find this answer anywhere.
Given the trivial example:
# myclass.py
class MyClass:
def __init__(self):
print 'test'
def main():
my_class_instance = MyClass()
if __name__ == '__main__':
main()
some_var = 'i exist! ... but I think I'm in global namespace?'
If I run bpython -i myclass.py, I execute the program & drop into the bpython environment. Whatever namespace I'm in - my_class_instance does not exist. However, some_var does exist - and so does the main function itself.
Is there anyway that I can pull any objects that exist in that main function into the namespace I'm in when I drop into that interactive prompt? Or is there something else I should do?
Using interactive bpython over python 2.7,
__name__
is equal to__console__
. So your functionmain()
may be never called. A hack would be to write: