Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Changing module variables in another module

Tags:

python

module

Say I am importing the module 'foo' into the module 'bar'. Is it possible for me to change a global variable in foo inside bar?

Let the global variable in foo be 'arbit'. Change arbit so that if bar were to call a function of foo that uses this variable, the updated variable is used rather than the one before that.

like image 257
Goutham Avatar asked Feb 05 '26 00:02

Goutham


1 Answers

You should be able to do:

import foo
foo.arbit = 'new value'
like image 163
Alice Purcell Avatar answered Feb 07 '26 15:02

Alice Purcell