Python Forum
Go to line starting with and variable not detected
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Go to line starting with and variable not detected
#1
Hi, how can I go a line starting with a precise word ? After my first condition, I need to go to the line starting with "/22/" (I have to browse my file in different directions) and add new_name to the new_line, but the result of my first condition isn't persisted through the code...

for fichier in os.listdir("result/"):
    if not fnmatch.fnmatch(fichier, 'file_0.txt'):
        with fileinput.input(["result/"+fichier], inplace=1) as file_X :
            # file_X.write('\r\ncoucou')
            print("---------------------------------")
            for line in file_X:
                line = line.strip('\n')
                if line.startswith("/54/"):
                    split = line.split("/")
                    num = split[2]
                    # print(num)
                    for pj in pjCSV:
                        if num in pj:
                            ...
                            new_name = "jacques"
                            sys.stderr.write(new_name + "\r\n")
                if line.startswith('/22/'):
                    new_line = line + new_name # new_name is not detected
                    print(line.replace(line, new_line))
                    continue
                print (line.rstrip('\n')) # ecriture de toutes les lignes
 
            break
Reply


Messages In This Thread
Go to line starting with and variable not detected - by morgandebray - Aug-08-2018, 02:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python not detected on computer adriennn 3 1,041 Nov-18-2023, 02:46 PM
Last Post: snippsat
  My .exe made using Python being detected as a virus 100grassfed 2 3,059 Jun-16-2021, 04:41 AM
Last Post: buran
  Finding line numbers starting with certain string Sutsro 3 2,575 Jun-27-2020, 12:36 PM
Last Post: Yoriz
  python --version yields no output, not detected by other programs ten 3 3,478 Jun-25-2020, 04:48 AM
Last Post: perfringo
  "Widget Javascript not detected" error BobLoblaw 0 4,325 Oct-07-2017, 04:48 PM
Last Post: BobLoblaw
  Object Detection that records the number of secs the face is not detected trabis03 1 2,560 Jul-21-2017, 04:14 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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