Начнем с того, что вы не должны использовать -
в объявлениях переменных, так как на самом деле это оператор и всегда будет рассматриваться как таковой. Он попытается вычесть.
Вот тот же код с исправленным, а также с входным значением
import os, re
config_file = "jsm_gyro_config.txt"
#fptr = open(config, "w")
#text = "demo text"
#fptr.write(text)
#fptr.close()
file = open(config_file, 'r')
file_read = file.read()
file.close() # You should always close your files.
for line in file_read:
if re.search(userinput, file_read):
x = re.search(userinput, file_read)
# iteminputted is what the user wants to replace
iteminputted = input("Input what you would like to replace > ")
startpostion = x.span[1] + 3
endpostion = startposition + len(iteminputted)
# Find out how to write to a specific location in a file that will finish this off
else:
print("Item not found")
Однако ваш вопрос очень неясен, я сделал все, что мог.