Shared module variable doesn't update?Calling a function of a module by using its name (a string)Are static class variables possible in Python?How do I return multiple values from a function?Using global variables in a functionHow do I unload (reload) a Python module?How can I get a list of locally installed Python modules?How do I pass a variable by reference?Pipe subprocess standard output to a variableHow to access environment variable values?python package structure and global variables
Why are some Mac apps not available on AppStore?
Is there any detail about ambulances in Star Wars?
What is Japanese Language Stack Exchange called in Japanese?
Does the word “uzi” need to be capitalized?
Can I disable a battery powered device by reversing half of its batteries?
How flexible are number-of-pages submission guidelines for conferences?
Can a magnet rip protons from a nucleus?
RP Automatic Updates
Do all humans have an identical nucleotide sequence for certain proteins, e.g haemoglobin?
How does Vivi differ from other Black Mages?
Does the wording of the Wrathful Smite spell imply that there are other living beings that aren't considered "creatures"?
How to split a string by the third .(dot) delimiter
Dividing Divisive Divisors
Was Robin Hood's point of view ethically sound?
Procedure for traffic not in sight
Are the definite and indefinite integrals actually two different things? Where is the flaw in my understanding?
Two different colors in an Illustrator stroke / line
Can a level 1 Fiend Pact warlock cast a scroll of fireball?
For how long could UK opposition parties prevent new elections?
Calculate time difference between two dates
How should we understand "unobscured by flying friends" in this context?
How to progress with CPLEX/Gurobi
Determining if file in projected or geographic coordinates using ArcGIS Desktop?
Why is the the worst case for this function O(n^2)?
Shared module variable doesn't update?
Calling a function of a module by using its name (a string)Are static class variables possible in Python?How do I return multiple values from a function?Using global variables in a functionHow do I unload (reload) a Python module?How can I get a list of locally installed Python modules?How do I pass a variable by reference?Pipe subprocess standard output to a variableHow to access environment variable values?python package structure and global variables
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to share (set/get) a variable between packages and modules, but the value isn't changing.
What am I doing wrong?
shared.py
my_shared_value = 'init'
mod_write.py
import mylib.shared
mylib.shared.my_shared_value = 'changed'
mod_read.py
import mylib.shared
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
Execution (same virtual environment)
# Terminal 1
python ./mod_read.py # outputs 'init', runs forever
# Terminal 2
python ./mod_write.py # doesn't affect the output of Terminal 1
python python-3.x module
|
show 1 more comment
I'm trying to share (set/get) a variable between packages and modules, but the value isn't changing.
What am I doing wrong?
shared.py
my_shared_value = 'init'
mod_write.py
import mylib.shared
mylib.shared.my_shared_value = 'changed'
mod_read.py
import mylib.shared
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
Execution (same virtual environment)
# Terminal 1
python ./mod_read.py # outputs 'init', runs forever
# Terminal 2
python ./mod_write.py # doesn't affect the output of Terminal 1
python python-3.x module
1
minimal reproducible example, please. Show us how you import and execute all of this code. Because there's nothing wrong with it.
– Aran-Fey
Mar 28 at 8:37
@Aran-Fey Thanks, I'll add more information.
– Mr. B.
Mar 28 at 8:38
@Aran-Fey I updated my answer. Does it help?
– Mr. B.
Mar 28 at 8:44
1
It does, yes. Thanks.
– Aran-Fey
Mar 28 at 8:44
2
Dupe: How to share variables across scripts in python?
– Aran-Fey
Mar 28 at 8:47
|
show 1 more comment
I'm trying to share (set/get) a variable between packages and modules, but the value isn't changing.
What am I doing wrong?
shared.py
my_shared_value = 'init'
mod_write.py
import mylib.shared
mylib.shared.my_shared_value = 'changed'
mod_read.py
import mylib.shared
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
Execution (same virtual environment)
# Terminal 1
python ./mod_read.py # outputs 'init', runs forever
# Terminal 2
python ./mod_write.py # doesn't affect the output of Terminal 1
python python-3.x module
I'm trying to share (set/get) a variable between packages and modules, but the value isn't changing.
What am I doing wrong?
shared.py
my_shared_value = 'init'
mod_write.py
import mylib.shared
mylib.shared.my_shared_value = 'changed'
mod_read.py
import mylib.shared
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
Execution (same virtual environment)
# Terminal 1
python ./mod_read.py # outputs 'init', runs forever
# Terminal 2
python ./mod_write.py # doesn't affect the output of Terminal 1
python python-3.x module
python python-3.x module
edited Mar 28 at 8:47
Mr. B.
asked Mar 28 at 8:35
Mr. B.Mr. B.
3,0665 gold badges36 silver badges67 bronze badges
3,0665 gold badges36 silver badges67 bronze badges
1
minimal reproducible example, please. Show us how you import and execute all of this code. Because there's nothing wrong with it.
– Aran-Fey
Mar 28 at 8:37
@Aran-Fey Thanks, I'll add more information.
– Mr. B.
Mar 28 at 8:38
@Aran-Fey I updated my answer. Does it help?
– Mr. B.
Mar 28 at 8:44
1
It does, yes. Thanks.
– Aran-Fey
Mar 28 at 8:44
2
Dupe: How to share variables across scripts in python?
– Aran-Fey
Mar 28 at 8:47
|
show 1 more comment
1
minimal reproducible example, please. Show us how you import and execute all of this code. Because there's nothing wrong with it.
– Aran-Fey
Mar 28 at 8:37
@Aran-Fey Thanks, I'll add more information.
– Mr. B.
Mar 28 at 8:38
@Aran-Fey I updated my answer. Does it help?
– Mr. B.
Mar 28 at 8:44
1
It does, yes. Thanks.
– Aran-Fey
Mar 28 at 8:44
2
Dupe: How to share variables across scripts in python?
– Aran-Fey
Mar 28 at 8:47
1
1
minimal reproducible example, please. Show us how you import and execute all of this code. Because there's nothing wrong with it.
– Aran-Fey
Mar 28 at 8:37
minimal reproducible example, please. Show us how you import and execute all of this code. Because there's nothing wrong with it.
– Aran-Fey
Mar 28 at 8:37
@Aran-Fey Thanks, I'll add more information.
– Mr. B.
Mar 28 at 8:38
@Aran-Fey Thanks, I'll add more information.
– Mr. B.
Mar 28 at 8:38
@Aran-Fey I updated my answer. Does it help?
– Mr. B.
Mar 28 at 8:44
@Aran-Fey I updated my answer. Does it help?
– Mr. B.
Mar 28 at 8:44
1
1
It does, yes. Thanks.
– Aran-Fey
Mar 28 at 8:44
It does, yes. Thanks.
– Aran-Fey
Mar 28 at 8:44
2
2
Dupe: How to share variables across scripts in python?
– Aran-Fey
Mar 28 at 8:47
Dupe: How to share variables across scripts in python?
– Aran-Fey
Mar 28 at 8:47
|
show 1 more comment
1 Answer
1
active
oldest
votes
To see the result of the mod_write.py file you need to import that file as well(but after your first import).
In your case, you execute files separately, so you don't see the expected result.
Try this way:
import mylib.shared
import mylib.mod_write
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55393164%2fshared-module-variable-doesnt-update%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To see the result of the mod_write.py file you need to import that file as well(but after your first import).
In your case, you execute files separately, so you don't see the expected result.
Try this way:
import mylib.shared
import mylib.mod_write
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
add a comment |
To see the result of the mod_write.py file you need to import that file as well(but after your first import).
In your case, you execute files separately, so you don't see the expected result.
Try this way:
import mylib.shared
import mylib.mod_write
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
add a comment |
To see the result of the mod_write.py file you need to import that file as well(but after your first import).
In your case, you execute files separately, so you don't see the expected result.
Try this way:
import mylib.shared
import mylib.mod_write
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
To see the result of the mod_write.py file you need to import that file as well(but after your first import).
In your case, you execute files separately, so you don't see the expected result.
Try this way:
import mylib.shared
import mylib.mod_write
while True:
# outputs always 'init' but should output 'changed'
# after mod_set.py was executed.
print(mylib.shared.my_shared_value)
answered Mar 28 at 8:56
Lusine MikayelyanLusine Mikayelyan
162 bronze badges
162 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55393164%2fshared-module-variable-doesnt-update%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
minimal reproducible example, please. Show us how you import and execute all of this code. Because there's nothing wrong with it.
– Aran-Fey
Mar 28 at 8:37
@Aran-Fey Thanks, I'll add more information.
– Mr. B.
Mar 28 at 8:38
@Aran-Fey I updated my answer. Does it help?
– Mr. B.
Mar 28 at 8:44
1
It does, yes. Thanks.
– Aran-Fey
Mar 28 at 8:44
2
Dupe: How to share variables across scripts in python?
– Aran-Fey
Mar 28 at 8:47