I have 2000 observations and 100 variables in my data from an empirical research project. I am currently doing data cleaning which involves recoding some variables for hundreds of my observations. Currently I am using this method below to change to do the cleaning:

foreach num in 1234 2345 3456 4567 5678 6789 ///
7891 8911 9110 1102 1103 1104 ///
{
replace q786 = 2 if obsid == `num'

}

As you can imagine I will have to enter the values of every single observation ID in the for loop just to do the same modification, for hundreds of observations for tens of variables.
I was trying to put all the ID in a text file so that I could import the text file using python code and go line-by -line doing the same modification which would save me time and make my code concise. However, I am not able to find information on how I could import the entire do file into my python code, modify variables for observations of interest and save back the modified do file to continue with stata. Can someone help me with this?
I am thinking about this approach:

python:
from sfi import Data
## sudo code
##import text file which contains IDs
##read IDs line by line
##replace the variable of interest with a new value
## save the dta file
## exit python