variable assigned at the end of a module











up vote
0
down vote

favorite












I have a quick question about how variables are passed from 1 module to another.



Scenarios:



I have 2 scripts, 1 name a.py and b.py.



## a.py
import datetime
import numpy as np
import os

class LOG:
testid = ""
log_f = None
perf_log_f = None

def __init__(self):
self.testid = ""

def setTestId (testid, log_f , perf_log_f):
log_v.testid = comp
log_v.log_f = open(log_f , 'w')
log_v.perf_log_f = open(perf_log_f, 'w')

log_v = LOG()


l is initiated



## b.py
from a import *

testid = 999
log_f = "kk.log"
perf_log_f = "kk_perf.log"
setTestId (testid, log_f , perf_log_f)

#### Does this setTestId do this step?
"log_v.log_f = open("kk.log", 'w')
"log_v.perf_log_f = open("kk_perf.log", 'w')


Make the amendment. So when I call setTestId (imported from a) into b.py, log_v = LOG() is only contained within a.py, right?



I would like to check if the the variable log_v in a.py will be overwritten if we assign log_v to another variable in b.py










share|improve this question




















  • 2




    assuming your indentation is correct the answer is no.
    – Red Cricket
    Nov 15 at 5:56










  • you are calling l.selfTestId on l but your method is not part of the class LOG. Check your indentation or refresh OOP concepts
    – Prakash Palnati
    Nov 15 at 5:58












  • Naming a variable "l" is too ambiguous, try to name it properly and for your answer it is no.
    – Vishnudev
    Nov 15 at 6:05










  • Let's put it this way: l in b.py will be exactly what l is in a.py.
    – deceze
    Nov 15 at 6:09










  • so the c = Clog() is contain within scripts a.py? and if I have a variable c in b.py, this is not related to the c in a.py>? I apologise for my bad OOP concepts. Also, the indentation is correct.
    – snookrun
    Nov 15 at 6:44















up vote
0
down vote

favorite












I have a quick question about how variables are passed from 1 module to another.



Scenarios:



I have 2 scripts, 1 name a.py and b.py.



## a.py
import datetime
import numpy as np
import os

class LOG:
testid = ""
log_f = None
perf_log_f = None

def __init__(self):
self.testid = ""

def setTestId (testid, log_f , perf_log_f):
log_v.testid = comp
log_v.log_f = open(log_f , 'w')
log_v.perf_log_f = open(perf_log_f, 'w')

log_v = LOG()


l is initiated



## b.py
from a import *

testid = 999
log_f = "kk.log"
perf_log_f = "kk_perf.log"
setTestId (testid, log_f , perf_log_f)

#### Does this setTestId do this step?
"log_v.log_f = open("kk.log", 'w')
"log_v.perf_log_f = open("kk_perf.log", 'w')


Make the amendment. So when I call setTestId (imported from a) into b.py, log_v = LOG() is only contained within a.py, right?



I would like to check if the the variable log_v in a.py will be overwritten if we assign log_v to another variable in b.py










share|improve this question




















  • 2




    assuming your indentation is correct the answer is no.
    – Red Cricket
    Nov 15 at 5:56










  • you are calling l.selfTestId on l but your method is not part of the class LOG. Check your indentation or refresh OOP concepts
    – Prakash Palnati
    Nov 15 at 5:58












  • Naming a variable "l" is too ambiguous, try to name it properly and for your answer it is no.
    – Vishnudev
    Nov 15 at 6:05










  • Let's put it this way: l in b.py will be exactly what l is in a.py.
    – deceze
    Nov 15 at 6:09










  • so the c = Clog() is contain within scripts a.py? and if I have a variable c in b.py, this is not related to the c in a.py>? I apologise for my bad OOP concepts. Also, the indentation is correct.
    – snookrun
    Nov 15 at 6:44













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a quick question about how variables are passed from 1 module to another.



Scenarios:



I have 2 scripts, 1 name a.py and b.py.



## a.py
import datetime
import numpy as np
import os

class LOG:
testid = ""
log_f = None
perf_log_f = None

def __init__(self):
self.testid = ""

def setTestId (testid, log_f , perf_log_f):
log_v.testid = comp
log_v.log_f = open(log_f , 'w')
log_v.perf_log_f = open(perf_log_f, 'w')

log_v = LOG()


l is initiated



## b.py
from a import *

testid = 999
log_f = "kk.log"
perf_log_f = "kk_perf.log"
setTestId (testid, log_f , perf_log_f)

#### Does this setTestId do this step?
"log_v.log_f = open("kk.log", 'w')
"log_v.perf_log_f = open("kk_perf.log", 'w')


Make the amendment. So when I call setTestId (imported from a) into b.py, log_v = LOG() is only contained within a.py, right?



I would like to check if the the variable log_v in a.py will be overwritten if we assign log_v to another variable in b.py










share|improve this question















I have a quick question about how variables are passed from 1 module to another.



Scenarios:



I have 2 scripts, 1 name a.py and b.py.



## a.py
import datetime
import numpy as np
import os

class LOG:
testid = ""
log_f = None
perf_log_f = None

def __init__(self):
self.testid = ""

def setTestId (testid, log_f , perf_log_f):
log_v.testid = comp
log_v.log_f = open(log_f , 'w')
log_v.perf_log_f = open(perf_log_f, 'w')

log_v = LOG()


l is initiated



## b.py
from a import *

testid = 999
log_f = "kk.log"
perf_log_f = "kk_perf.log"
setTestId (testid, log_f , perf_log_f)

#### Does this setTestId do this step?
"log_v.log_f = open("kk.log", 'w')
"log_v.perf_log_f = open("kk_perf.log", 'w')


Make the amendment. So when I call setTestId (imported from a) into b.py, log_v = LOG() is only contained within a.py, right?



I would like to check if the the variable log_v in a.py will be overwritten if we assign log_v to another variable in b.py







python class variables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 7:02









tripleee

87.6k12122177




87.6k12122177










asked Nov 15 at 5:52









snookrun

255




255








  • 2




    assuming your indentation is correct the answer is no.
    – Red Cricket
    Nov 15 at 5:56










  • you are calling l.selfTestId on l but your method is not part of the class LOG. Check your indentation or refresh OOP concepts
    – Prakash Palnati
    Nov 15 at 5:58












  • Naming a variable "l" is too ambiguous, try to name it properly and for your answer it is no.
    – Vishnudev
    Nov 15 at 6:05










  • Let's put it this way: l in b.py will be exactly what l is in a.py.
    – deceze
    Nov 15 at 6:09










  • so the c = Clog() is contain within scripts a.py? and if I have a variable c in b.py, this is not related to the c in a.py>? I apologise for my bad OOP concepts. Also, the indentation is correct.
    – snookrun
    Nov 15 at 6:44














  • 2




    assuming your indentation is correct the answer is no.
    – Red Cricket
    Nov 15 at 5:56










  • you are calling l.selfTestId on l but your method is not part of the class LOG. Check your indentation or refresh OOP concepts
    – Prakash Palnati
    Nov 15 at 5:58












  • Naming a variable "l" is too ambiguous, try to name it properly and for your answer it is no.
    – Vishnudev
    Nov 15 at 6:05










  • Let's put it this way: l in b.py will be exactly what l is in a.py.
    – deceze
    Nov 15 at 6:09










  • so the c = Clog() is contain within scripts a.py? and if I have a variable c in b.py, this is not related to the c in a.py>? I apologise for my bad OOP concepts. Also, the indentation is correct.
    – snookrun
    Nov 15 at 6:44








2




2




assuming your indentation is correct the answer is no.
– Red Cricket
Nov 15 at 5:56




assuming your indentation is correct the answer is no.
– Red Cricket
Nov 15 at 5:56












you are calling l.selfTestId on l but your method is not part of the class LOG. Check your indentation or refresh OOP concepts
– Prakash Palnati
Nov 15 at 5:58






you are calling l.selfTestId on l but your method is not part of the class LOG. Check your indentation or refresh OOP concepts
– Prakash Palnati
Nov 15 at 5:58














Naming a variable "l" is too ambiguous, try to name it properly and for your answer it is no.
– Vishnudev
Nov 15 at 6:05




Naming a variable "l" is too ambiguous, try to name it properly and for your answer it is no.
– Vishnudev
Nov 15 at 6:05












Let's put it this way: l in b.py will be exactly what l is in a.py.
– deceze
Nov 15 at 6:09




Let's put it this way: l in b.py will be exactly what l is in a.py.
– deceze
Nov 15 at 6:09












so the c = Clog() is contain within scripts a.py? and if I have a variable c in b.py, this is not related to the c in a.py>? I apologise for my bad OOP concepts. Also, the indentation is correct.
– snookrun
Nov 15 at 6:44




so the c = Clog() is contain within scripts a.py? and if I have a variable c in b.py, this is not related to the c in a.py>? I apologise for my bad OOP concepts. Also, the indentation is correct.
– snookrun
Nov 15 at 6:44












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










I figured it out.



LOG() class is initiated at importing of a.py. It is assigned to the instance log_v



In b.py, when I call the functions setTestId (testid, log_f , perf_log_f), it passes the arguments, testid, log_f , perf_log_f to log_v to a.py and allow the initialization of the class with these variables.



Hence suppose I have a new functions logging() in a.py that uses log_v, by simply importing a.py and call the function logging(), I am able to access the class LOG() using the instance log_v that is contained within a.py and make any modification or updates to the class. This log_v is also protected from the scripts in b.py so it does not get overwritten if we also have another instance or variable name log_v in b.py






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',
    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/3.0/"u003ecc by-sa 3.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%2f53313227%2fvariable-assigned-at-the-end-of-a-module%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








    up vote
    0
    down vote



    accepted










    I figured it out.



    LOG() class is initiated at importing of a.py. It is assigned to the instance log_v



    In b.py, when I call the functions setTestId (testid, log_f , perf_log_f), it passes the arguments, testid, log_f , perf_log_f to log_v to a.py and allow the initialization of the class with these variables.



    Hence suppose I have a new functions logging() in a.py that uses log_v, by simply importing a.py and call the function logging(), I am able to access the class LOG() using the instance log_v that is contained within a.py and make any modification or updates to the class. This log_v is also protected from the scripts in b.py so it does not get overwritten if we also have another instance or variable name log_v in b.py






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      I figured it out.



      LOG() class is initiated at importing of a.py. It is assigned to the instance log_v



      In b.py, when I call the functions setTestId (testid, log_f , perf_log_f), it passes the arguments, testid, log_f , perf_log_f to log_v to a.py and allow the initialization of the class with these variables.



      Hence suppose I have a new functions logging() in a.py that uses log_v, by simply importing a.py and call the function logging(), I am able to access the class LOG() using the instance log_v that is contained within a.py and make any modification or updates to the class. This log_v is also protected from the scripts in b.py so it does not get overwritten if we also have another instance or variable name log_v in b.py






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        I figured it out.



        LOG() class is initiated at importing of a.py. It is assigned to the instance log_v



        In b.py, when I call the functions setTestId (testid, log_f , perf_log_f), it passes the arguments, testid, log_f , perf_log_f to log_v to a.py and allow the initialization of the class with these variables.



        Hence suppose I have a new functions logging() in a.py that uses log_v, by simply importing a.py and call the function logging(), I am able to access the class LOG() using the instance log_v that is contained within a.py and make any modification or updates to the class. This log_v is also protected from the scripts in b.py so it does not get overwritten if we also have another instance or variable name log_v in b.py






        share|improve this answer












        I figured it out.



        LOG() class is initiated at importing of a.py. It is assigned to the instance log_v



        In b.py, when I call the functions setTestId (testid, log_f , perf_log_f), it passes the arguments, testid, log_f , perf_log_f to log_v to a.py and allow the initialization of the class with these variables.



        Hence suppose I have a new functions logging() in a.py that uses log_v, by simply importing a.py and call the function logging(), I am able to access the class LOG() using the instance log_v that is contained within a.py and make any modification or updates to the class. This log_v is also protected from the scripts in b.py so it does not get overwritten if we also have another instance or variable name log_v in b.py







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 0:27









        snookrun

        255




        255






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53313227%2fvariable-assigned-at-the-end-of-a-module%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

            mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?