How is MSN a new variable? It is not intended to be.
If line 8 is commented out, it is printable in all three locations.
If line 8 is not commented out, then MSN in the previous line is determined to be undeclared.
It looks as if I am not allowed to change the contents of the variable MSN.
FootNote:
If money does not grow on trees, then why do banks have branches?
From: Souvik Dutta <souvik.viksou@gmail.com>
Sent: Tuesday, August 4, 2020 5:12 AM
To: Steve <Gronicus@sga.ninja>
Subject: Re: Updating a variable problem.
I don't know your exact meaning of fail. But as much as I can say there is a new variable MSN being declared in the function that is only seen locally that is inside the function. Now python sees this and probably says variable used before assigning. You might try declaring a global msn in the function again. And then changing msn after the print statement. Also this error occurred because python first searches the variable in the local scope which is absent earlier and so it searches for the variable in the global scope where it is present and so no errors are raised.
Souvik flutter dev
On Tue, Aug 4, 2020, 2:30 PM Steve <Gronicus@sga.ninja <mailto:Gronicus@sga.ninja> > wrote:
The print statement works in the EditTheEQlist() therefore the variable is seen as having been declared. If I replace the value in the variable in the next line then the print statement fails. Is this still a matter of globality?
If it is, how do I fix it?
FootNote:
If money does not grow on trees, then why do banks have branches?
From: Souvik Dutta <souvik.viksou@gmail.com <mailto:souvik.viksou@gmail.com> >
Sent: Tuesday, August 4, 2020 4:50 AM
To: Steve <Gronicus@sga.ninja <mailto:Gronicus@sga.ninja> >
Cc: Python List <python-list@python.org <mailto:python-list@python.org> >
Subject: Re: Updating a variable problem.
Probably because the MSN variable in the second function is not global.
On Tue, Aug 4, 2020, 2:08 PM Steve <Gronicus@sga.ninja <mailto:Gronicus@sga.ninja> > wrote:
Why should line 6 fail until line 7 is commented out?
Python complains that MSN is "referenced before assignment".
def ReadTheEQfile():
global MSN
MSN = ("1 Monitor") #This line works every time.
def EditTheEQlist():
print("MSN2 = " + MSN) # Works if the next line is commented out.
MSN = ("3 Monitor")
# Main()
ReadTheEQfile()
print("MSN1 = " + MSN) # This line works every time
EditTheEQlist()
=====================================
Footnote:
Genie: You have three wishes.
Me: I wish I had more wishes.
Genie: You cannot wish for more wishes.
Me: I wish I could.
--
https://mail.python.org/mailman/listinfo/python-list --
https://mail.python.org/mailman/listinfo/python-list