Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Get True of false outside a loop
#1
Hi, how can i get the value of each variable that i'm creating in my loop ? I have this :
for fichier in os.listdir("result/"):
    if not fnmatch.fnmatch(fichier, 'file_0.txt'):

        #récupération de valeur
        with fileinput.input(["result/"+fichier], inplace=1) as file_X :
            # file_X.write('\r\ncoucou')
            print("------Récupération de variable-------")
            for line in file_X:
                balise02R = False
                balise191Absente = True
                line = line.strip('\n')
                if line.startswith('/02/R'):
                    balise02R = True
                    sys.stderr.write("Balise 02 présente /02/R\r\n")
                if line.startswith("/20/"):
                    splitLigne20 = line.split("/")
                    valeur20 = splitLigne20[2]
                if line.startswith("/66/"):
                    splitLigne66 = line.split("/")
                    valeur66 = splitLigne66[2]
                if line.startswith("/191/"):
                    balise191Absente = False
                    sys.stderr.write("Balise 191 présente\r\n")
                print (line.rstrip('\n'))
            # break

        if balise02R == True and balise191Absente == True:
        sys.stderr.write("balise 02 " + str(balise02R) + " / balise 191 " + str(balise191Absente) +"\r\n")
        ...
But variable balise02R hasn't the right value (but it's indead equals to True in trace). I tried break, continue and pass but nothing, any advice ?
Quote
#2
perhaps it would be easier understood if you:
  • show several lines of the file verbatim
  • give a list of what you want to match in each line
Then your code will be easier to comprehend.
Quote
#3
I've got the solution, I changed some variable to true to false and my 2 variables are now declared outside the for :
        with fileinput.input(["result/"+fichier], inplace=1) as file_X :
            balise02R = False
            balise191Presente = False
            for line in file_X:
                line = line.strip('\n')
                if line.startswith('/02/R'):
                    balise02R = True
                if line.startswith("/20/"):
                    splitLigne20 = line.split("/")
                    valeur20 = splitLigne20[2]
                if line.startswith("/66/"):
                    splitLigne66 = line.split("/")
                    valeur66 = splitLigne66[2]
                if line.startswith("/191/"):
                    balise191Presente = True
                print (line.rstrip('\n'))


        if balise02R == True and balise191Presente == True:
            conditionInitial = True
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to use while true/while loop on python christing 4 173 Oct-08-2019, 08:02 AM
Last Post: perfringo
  Returning True or False vs. True or None trevorkavanaugh 6 469 Apr-04-2019, 08:42 AM
Last Post: DeaD_EyE
  file.write stops while true loop from executing in python3 boonr 3 331 Mar-25-2019, 12:50 PM
Last Post: ichabod801
  How to make loop go back to the beginning if test evaluaes to True. FWendeburg 1 359 Feb-13-2019, 01:26 AM
Last Post: stullis
  Returning true or false in a for loop bbop1232012 3 442 Nov-22-2018, 04:44 PM
Last Post: bbop1232012
  True == not False Skaperen 6 796 Aug-23-2018, 10:26 AM
Last Post: DeaD_EyE
  saving a true/false of a single value Skaperen 3 517 Aug-20-2018, 02:31 AM
Last Post: ichabod801
  True or false if running something? Artdigy 4 937 Mar-27-2018, 05:50 PM
Last Post: nilamo
  True vs False Skaperen 10 2,777 Jun-14-2017, 09:56 AM
Last Post: wavic
  How to turn variable true and false using function? hsunteik 5 1,834 Feb-20-2017, 11:44 AM
Last Post: hsunteik

Forum Jump:


Users browsing this thread: 1 Guest(s)