0

While running this code inside a function, Globals() are not updated.

fpath= dir1+'/data1_.spydata'
globals().update(load_dictionary(fpath)[0])

When running outside, as a script, globals() is updated. How to make it run from a function ?

Thanks

tensor
  • 3,088
  • 8
  • 37
  • 71
  • 2
    Simple answer : don't. globals are evil. – bruno desthuilliers Oct 27 '16 at 12:29
  • 1
    You definitely can update `globals()` from a function, though I would refrain from it by all means. – bereal Oct 27 '16 at 12:29
  • 1
    It should work from a function. Can you provide a [mcve]? – Alex Hall Oct 27 '16 at 12:30
  • You should probably declare the variable as a global in the [beginning of the function](http://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them). But if you can [avoid globals](http://stackoverflow.com/questions/19158339/why-are-global-variables-evil) – berna1111 Oct 27 '16 at 12:34
  • This is to load variables into globals()..... Not about Global variables, it seems there is a lot of confusion in the answers. – tensor Oct 27 '16 at 15:22

0 Answers0