1

Edit to make it better understandable:

My file is looking something like this:

For M5|Adr    11|KD1               12:29:09    1|     
For M5|Adr    12|KD1  8964523      12:34:173   1|Lr   
For M5|Adr    13|KD1     1000      12:34:563   1|Lv   
For M5|Adr    14|KD1  bvff123      12:34:56    1|     
For M5|Adr    15|KD1               12:39:063   1|Lr   

I found out which lines need to be edited and put them into a list.

templist = list(range(anfzahl+3, endzahl-4))

Templist defines the part of the file which needs to be edited for example: Starting with line 5 until line 15.

The part which needs to be replaced with spaces is for example in this case: 8964523, 1000 and bvff123. There can stand any letter and any number or it can already be blank, it is limited to column 23 to 30 tho.

Now I am looking for a function which can (in this example) edit everything in column 23 to 30 from line 5 to line 15 and replace it with spaces.

Thanks in advance for the read and help.

  • Look at my answer on this [post](https://stackoverflow.com/a/73547491/3155240), which is about deleting specific lines. I don't think there is a function that exists to do what you want -> ie your going to have to code it, so please include any attempt you've made in your post. – Shmack Jan 02 '23 at 18:55
  • Do you mean you want to edit the file in-place without reading and rewriting it all? This *is* one of the few transformations that can be made that way, at least for certain choices of encoding and characters (but it might be easier to rewrite it all anyway if that’s not too expensive). – Davis Herring Jan 02 '23 at 19:08
  • What do you suggest if we consider r, w and r+? – swiss army knive Jan 02 '23 at 19:29

1 Answers1

0

how about this does this helps

some_list = [
"For M5|Adr    11|KD1               12:29:09    1|",
"For M5|Adr    12|KD1  8964523      12:34:173   1|Lr",
"For M5|Adr    13|KD1     1000      12:34:563   1|Lv",
"For M5|Adr    14|KD1  bvff123      12:34:56    1|",
"For M5|Adr    15|KD1               12:39:063   1|Lr"
]
some_str = some_list[1].replace("8964523", '')
some_list[1] = some_str
print(some_list)