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;








1















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









share|improve this question





















  • 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















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









share|improve this question





















  • 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








1








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









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












1 Answer
1






active

oldest

votes


















0
















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)





share|improve this answer
























    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
    );



    );














    draft saved

    draft discarded
















    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









    0
















    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)





    share|improve this answer





























      0
















      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)





      share|improve this answer



























        0














        0










        0









        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)





        share|improve this answer













        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)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 8:56









        Lusine MikayelyanLusine Mikayelyan

        162 bronze badges




        162 bronze badges





















            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.




















            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript