Python Forum
Variable being erased inside of if statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variable being erased inside of if statement
#1
On the program I'm currently working on I have a variable that disappears at an if statement and I can't figure out why. Here is sort of what the code looks like:

while (iteration_index < data_iterations):
	
    Do some stuff...

	for something in something_else:
        
        my_variable = something
	   
        Do more stuff...
        print(my_variable) # variable still there
		
        for something_else_2 in more_things:

		    filter_a_dataframe = an_unfiltered_dataframe
          
            print(my_variable) #still looks good
			
            if (not filter_a_dataframe.empty):
                print(my_variable) #my_variable has been erased here
				break
			else:
				continue
Oddly, if the if statement changes from
if (not filter_a_dataframe.empty) 
to
if (filter_a_dataframe.empty)
the variable doesn't get erased. Any ideas why this is happening? Also, I can provide the specific code if that helps. I was just trying to simplify it for easy reading.
Reply


Messages In This Thread
Variable being erased inside of if statement - by deusablutum - Jun-09-2024, 07:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 598 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 2,465 Nov-07-2023, 09:49 AM
Last Post: buran
  Cursor Variable inside Another Cursor . CX_ORacle paulo79 1 1,649 Apr-09-2022, 10:24 AM
Last Post: ibreeden
  An IF statement with a List variable dedesssse 3 8,964 Jul-08-2021, 05:58 PM
Last Post: perfringo
  define a variable using an if statement Margaridalopes 2 2,296 Oct-24-2020, 05:47 PM
Last Post: jefsummers
  Correct syntax for a variable inside a quotes: MP4Box command JonnyDriller 2 2,893 Feb-02-2020, 01:22 AM
Last Post: JonnyDriller
  How to store the value from variable into list & run a statement then put in variable searching1 1 2,570 May-29-2019, 06:36 AM
Last Post: heiner55
  Get variable from class inside another class hcne 3 2,966 Mar-30-2019, 03:02 PM
Last Post: ichabod801
  SELECT statement query question using a variable DT2000 2 3,175 Feb-23-2019, 07:35 AM
Last Post: DT2000
  Invalid syntax in two variable if statement? 00712411 1 2,373 Oct-10-2018, 12:36 AM
Last Post: stullis

Forum Jump:

User Panel Messages

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