LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find location of wanted string in file and append new string below

Hi guys,

I'm trying to append line to existing python file but I'm having issues finding the commands I need to do so.

I want my program to:

Open the python file, read it to text, search for the string 'enter sizes below' and then append my string in a new line.

vi.JPG

Unfortunately, I couldn't find the right command that will allow me to set the file position right after the word 'below' and then append.

I'm attaching the python code as well.below.JPG

Thanks!

 

0 Kudos
Message 1 of 3
(2,350 Views)

You can't do that directly in the file (unless it ends with the searched for file), so what you need to do it:

Read all of the file as string

Search for your text and cut the string at this point to part 1 and part 2

Build a new string with Part 1 + your insert + part 2

Write this new string to file.

 

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 3
(2,340 Views)

Well, there it is... I never thought I'd see the day when text-based code would be presented as a picture... 😄

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 3
(2,337 Views)