Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resetting Global Variables?
#3
It seems that I have found some workaround or a solution. Haven't quite figured out yet why it necessarily works, but if anyone could explain that would be awesome. So I moved my variables that need to be global to their own function (since they need to use functions anyhow to obtain the correct value). After declaring their own global variables in their respective functions, it seems that I was then able to update my global variable properly. Here is what I did.

def FindVin():
    global Vin
    Vin = str(CustomerIndex[int(float(LoadedSales['CC'][InxLoc]))][2])[-8:]
    return Vin
And the main Function before FindVin is called.

            def Main():
                CustomerSaleID = CustomerSaleOBJID()
                Vin = FindVin()
                FPnum = FindFPnum()

(Sep-28-2018, 04:31 PM)micseydel Wrote: Why are you using global variables? They're notoriously hard to debug, and often viewed as poor code architecture.

If I inherited that code and had to fix it, I'd start removing the global variables just to wrap my head around how things work. Have you tried removing them? We can potentially help you move away from them, but personally I wouldn't even try to debug them as-is.

I posted right as you did so I didn't see your post before I had posted my own response. I cannot find a good source tutorial on how to properly use variables outside/with other functions. How would you use a variable globally without being global?
Reply


Messages In This Thread
Resetting Global Variables? - by WuchaDoin - Sep-28-2018, 03:12 PM
RE: Resetting Global Variables? - by micseydel - Sep-28-2018, 04:31 PM
RE: Resetting Global Variables? - by WuchaDoin - Sep-28-2018, 04:35 PM
RE: Resetting Global Variables? - by ichabod801 - Sep-28-2018, 05:14 PM
RE: Resetting Global Variables? - by WuchaDoin - Sep-28-2018, 05:20 PM
RE: Resetting Global Variables? - by nilamo - Sep-28-2018, 06:41 PM
RE: Resetting Global Variables? - by WuchaDoin - Sep-28-2018, 06:59 PM
RE: Resetting Global Variables? - by nilamo - Sep-28-2018, 07:09 PM
RE: Resetting Global Variables? - by WuchaDoin - Sep-28-2018, 07:50 PM
RE: Resetting Global Variables? - by ichabod801 - Sep-28-2018, 08:34 PM
RE: Resetting Global Variables? - by WuchaDoin - Sep-28-2018, 08:41 PM
RE: Resetting Global Variables? - by volcano63 - Sep-28-2018, 08:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand global variables 357mag 5 1,236 May-12-2023, 04:16 PM
Last Post: deanhystad
  Global variables or local accessible caslor 4 1,119 Jan-27-2023, 05:32 PM
Last Post: caslor
  global variables HeinKurz 3 1,230 Jan-17-2023, 06:58 PM
Last Post: HeinKurz
  Clarity on global variables JonWayn 2 1,015 Nov-26-2022, 12:10 PM
Last Post: JonWayn
  resetting an iterator to full Skaperen 7 7,260 Feb-20-2022, 11:11 PM
Last Post: Skaperen
  variables vcnt, ocnt, and mcnt adding previous values and not resetting to 0 archanut 2 2,008 Feb-12-2021, 06:56 PM
Last Post: deanhystad
  Global variables not working hobbyist 9 4,881 Jan-16-2021, 03:17 PM
Last Post: jefsummers
  Global vs. Local Variables Davy_Jones_XIV 4 2,734 Jan-06-2021, 10:22 PM
Last Post: Davy_Jones_XIV
  Global - local variables Motorhomer14 11 4,410 Dec-17-2020, 06:40 PM
Last Post: Motorhomer14
  Question regarding local and global variables donmerch 12 5,276 Apr-12-2020, 03:58 PM
Last Post: TomToad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020